Skip to content

Commit

Permalink
Autoscroll suggestion list when navigating the emoji suggestions
Browse files Browse the repository at this point in the history
Navigating the suggestion list via arrow up/down keys is handled in
javascript, so we have to handle the scrolling in javascript too.

Only scrolls if the new selected item has not visible before.
At ArrowDown, scroll bottom of visible area to lower border of item.
At ArrowUp, scroll top of visible area to upper border of item.

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Feb 22, 2022
1 parent 908c736 commit b05c62b
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/components/EmojiList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,38 @@ export default {
hasResults() {
return this.items.length > 0
},
itemHeight() {
return this.$el.scrollHeight / this.items.length
},
itemInsideScrollView() {
// If upper border of item is bigger or equal than scroll top
// and lower end of item is smaller or equal than scroll bottom
return this.selectedIndex * this.itemHeight >= this.$el.scrollTop
&& (this.selectedIndex + 1) * this.itemHeight <= this.$el.scrollTop + this.$el.clientHeight
},
},
watch: {
items() {
this.selectedIndex = 0
this.$el.scrollTop = 0
},
},
methods: {
t,
onKeyDown({ event }) {
if (event.key === 'ArrowUp') {
this.selectedIndex = ((this.selectedIndex + this.items.length) - 1) % this.items.length
if (!this.itemInsideScrollView) {
this.$el.scrollTop = this.selectedIndex * this.itemHeight
}
return true
}
if (event.key === 'ArrowDown') {
this.selectedIndex = (this.selectedIndex + 1) % this.items.length
if (!this.itemInsideScrollView) {
this.$el.scrollTop = (this.selectedIndex + 1) * this.itemHeight - this.$el.clientHeight
}
return true
}
Expand Down

0 comments on commit b05c62b

Please sign in to comment.