Skip to content

Commit

Permalink
fix(NcRichContenteditable): Fix tribute emoji complete interfering un…
Browse files Browse the repository at this point in the history
…expectedly aka. Cocos Island Meme

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 24, 2023
1 parent 4690b32 commit 28f4500
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/components/NcRichContenteditable/NcRichContenteditable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export default {
data() {
return {
textEmojis: [],
tribute: null,
autocompleteOptions: {
// Allow spaces in the middle of mentions
Expand All @@ -273,16 +274,32 @@ export default {
// Where to inject the menu popup
menuContainer: this.menuContainer,
// Popup mention autocompletion templates
menuItemTemplate: item => `<span class="tribute-container-emoji__item__emoji">${item.original.native}</span> :${item.original.short_name}`,
menuItemTemplate: item => {
if (this.textEmojis.includes(item.original)) {
return item.original
}
return `<span class="tribute-container-emoji__item__emoji">${item.original.native}</span> :${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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 28f4500

Please sign in to comment.