diff --git a/webapp/components/Editor/Editor.vue b/webapp/components/Editor/Editor.vue index 1d601da42..d08257347 100644 --- a/webapp/components/Editor/Editor.vue +++ b/webapp/components/Editor/Editor.vue @@ -4,14 +4,13 @@ @@ -24,6 +23,9 @@ import { Editor, EditorContent } from 'tiptap' import { History } from 'tiptap-extensions' import linkify from 'linkify-it' import stringHash from 'string-hash' + +import * as key from '../../constants/keycodes' +import { HASHTAG, MENTION } from '../../constants/editor' import defaultExtensions from './defaultExtensions.js' import EventHandler from './plugins/eventHandler.js' import Hashtag from './nodes/Hashtag.js' @@ -34,8 +36,6 @@ import SuggestionList from './SuggestionList' import LinkInput from './LinkInput' let throttleInputEvent -const HASHTAG = 'hashtag' -const MENTION = 'mention' export default { components: { @@ -74,12 +74,6 @@ export default { showSuggestions() { return this.query || this.hasResults }, - isMention() { - return this.suggestionType === MENTION - }, - isHashtag() { - return this.suggestionType === HASHTAG - }, optionalExtensions() { const extensions = [] // Don't change the following line. The functionallity is in danger! @@ -182,21 +176,28 @@ export default { this.$refs.contextMenu.hideContextMenu() }, navigateSuggestionList({ event }) { + const item = this.filteredItems[this.navigatedItemIndex] + switch (event.keyCode) { - case 38: - this.handleUpArrow() + case key.ARROW_UP: + this.navigatedItemIndex = + (this.navigatedItemIndex + this.filteredItems.length - 1) % this.filteredItems.length return true - case 40: - this.handleDownArrow() + case key.ARROW_DOWN: + this.navigatedItemIndex = (this.navigatedItemIndex + 1) % this.filteredItems.length return true - case 13: - this.handleEnter() + case key.RETURN: + if (item) { + this.selectItem(item) + } return true - case 32: - this.handleSpace() + case key.SPACE: + if (this.suggestionType === HASHTAG && this.query !== '') { + this.selectItem({ id: this.query }) + } return true default: @@ -222,24 +223,6 @@ export default { } return query }, - handleUpArrow() { - this.navigatedItemIndex = - (this.navigatedItemIndex + this.filteredItems.length - 1) % this.filteredItems.length - }, - handleDownArrow() { - this.navigatedItemIndex = (this.navigatedItemIndex + 1) % this.filteredItems.length - }, - handleEnter() { - const item = this.filteredItems[this.navigatedItemIndex] - if (item) { - this.selectItem(item) - } - }, - handleSpace() { - if (this.suggestionType === HASHTAG && this.query !== '') { - this.selectItem({ id: this.query }) - } - }, // we have to replace our suggestion text with a mention // so it's important to pass also the position of your suggestion text selectItem(item) { diff --git a/webapp/components/Editor/SuggestionList.vue b/webapp/components/Editor/SuggestionList.vue index 54877acc3..5eed66c79 100644 --- a/webapp/components/Editor/SuggestionList.vue +++ b/webapp/components/Editor/SuggestionList.vue @@ -1,5 +1,5 @@