From 28f450078dc378cb649c58370770617dad764e0f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 24 Mar 2023 07:26:31 +0100 Subject: [PATCH] fix(NcRichContenteditable): Fix tribute emoji complete interfering unexpectedly aka. Cocos Island Meme Signed-off-by: Joas Schilling --- .../NcRichContenteditable.vue | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/components/NcRichContenteditable/NcRichContenteditable.vue b/src/components/NcRichContenteditable/NcRichContenteditable.vue index 5015cafec5..be4340b2ce 100644 --- a/src/components/NcRichContenteditable/NcRichContenteditable.vue +++ b/src/components/NcRichContenteditable/NcRichContenteditable.vue @@ -247,6 +247,7 @@ export default { data() { return { + textEmojis: [], tribute: null, autocompleteOptions: { // Allow spaces in the middle of mentions @@ -273,16 +274,32 @@ export default { // Where to inject the menu popup menuContainer: this.menuContainer, // Popup mention autocompletion templates - menuItemTemplate: item => `${item.original.native} :${item.original.short_name}`, + menuItemTemplate: item => { + if (this.textEmojis.includes(item.original)) { + return item.original + } + + return `${item.original.native} :${item.original.short_name}` + }, // Hide if no results noMatchTemplate: () => t('No emoji found'), // Display raw emoji along with its name selectTemplate: (item) => { + if (this.textEmojis.includes(item.original)) { + return item.original + } + emojiAddRecent(item.original) return item.original.native }, // Pass the search results as values - values: (text, cb) => cb(emojiSearch(text)), + values: (text, cb) => { + const emojiResults = emojiSearch(text) + if (this.textEmojis.includes(':' + text)) { + emojiResults.unshift(':' + text) + } + cb(emojiResults) + }, // Class added to the menu container containerClass: 'tribute-container-emoji', // Class added to each list item @@ -388,6 +405,13 @@ export default { }, mounted() { + const emojiCharacters = ['D', 'P', 'S', 'X', ')', '(', '/'] + this.textEmojis = [] + emojiCharacters.forEach((char) => { + this.textEmojis.push(':' + char) + this.textEmojis.push(':-' + char) + }) + this.autocompleteTribute = new Tribute(this.autocompleteOptions) this.autocompleteTribute.attach(this.$el)