From b95bb64ecf7073e9c76e2d1e1665aa37decb4177 Mon Sep 17 00:00:00 2001 From: solidsanek Date: Fri, 14 Oct 2022 01:40:23 +0200 Subject: [PATCH] Add mfm autocomplete --- src/components/emoji_input/emoji_input.js | 3 +-- src/components/emoji_input/emoji_input.vue | 2 +- src/components/emoji_input/suggestor.js | 12 ++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/emoji_input/emoji_input.js b/src/components/emoji_input/emoji_input.js index 78e75880..846274b8 100644 --- a/src/components/emoji_input/emoji_input.js +++ b/src/components/emoji_input/emoji_input.js @@ -178,7 +178,7 @@ const EmojiInput = { textAtCaret: async function (newWord) { const firstchar = newWord.charAt(0) this.suggestions = [] - if (newWord === firstchar) return + if (newWord === firstchar && firstchar !== '$') return const matchedSuggestions = await this.suggest(newWord) // Async: cancel if textAtCaret has changed during wait if (this.textAtCaret !== newWord) return @@ -277,7 +277,6 @@ const EmojiInput = { }, replaceText (e, suggestion) { const len = this.suggestions.length || 0 - if (this.textAtCaret.length === 1) { return } if (len > 0 || suggestion) { const chosenSuggestion = suggestion || this.suggestions[this.highlighted] const replacement = chosenSuggestion.replacement diff --git a/src/components/emoji_input/emoji_input.vue b/src/components/emoji_input/emoji_input.vue index 7d95ab7e..078253c2 100644 --- a/src/components/emoji_input/emoji_input.vue +++ b/src/components/emoji_input/emoji_input.vue @@ -42,7 +42,7 @@ :class="{ highlighted: index === highlighted }" @click.stop.prevent="onClick($event, suggestion)" > - + ({ displayText: tag, detailText: '$[' + tag + ' ]', replacement: '$[' + tag + ' ]', mfm: true })) + /** * suggest - generates a suggestor function to be used by emoji-input * data: object providing source information for specific types of suggestions: @@ -12,6 +15,7 @@ export default data => { const emojiCurry = suggestEmoji(data.emoji) + const mfmCurry = suggestMfm() const usersCurry = data.store && suggestUsers(data.store) return input => { const firstChar = input[0] @@ -21,10 +25,18 @@ export default data => { if (firstChar === '@' && usersCurry) { return usersCurry(input) } + if (firstChar === '$' && mfmCurry) { + return mfmCurry(input) + } return [] } } +export const suggestMfm = () => input => { + return MFM_TAGS + .filter(({ replacement }) => replacement.toLowerCase().indexOf(input) !== -1) +} + export const suggestEmoji = emojis => input => { const noPrefix = input.toLowerCase().substr(1) return emojis