diff --git a/src/components/emoji_picker/emoji_picker.js b/src/components/emoji_picker/emoji_picker.js index 5c09f6ca7b..713ecd8bb4 100644 --- a/src/components/emoji_picker/emoji_picker.js +++ b/src/components/emoji_picker/emoji_picker.js @@ -8,10 +8,17 @@ const LOAD_EMOJI_BY = 60 const LOAD_EMOJI_MARGIN = 64 const filterByKeyword = (list, keyword = '') => { + if (keyword === '') return list + const keywordLowercase = keyword.toLowerCase() - return list.filter(emoji => - emoji.displayText.toLowerCase().includes(keywordLowercase) - ) + const orderedEmojiList = [] + for (const emoji of list) { + const indexOfKeyword = emoji.displayText.toLowerCase().indexOf( keywordLowercase ) + if ( indexOfKeyword > -1 ) { + orderedEmojiList.splice(indexOfKeyword, 0, emoji) + } + } + return orderedEmojiList } const EmojiPicker = { diff --git a/src/components/react_button/react_button.js b/src/components/react_button/react_button.js index abcf04555c..473a2506d4 100644 --- a/src/components/react_button/react_button.js +++ b/src/components/react_button/react_button.js @@ -29,9 +29,14 @@ const ReactButton = { emojis () { if (this.filterWord !== '') { const filterWordLowercase = this.filterWord.toLowerCase() - return this.$store.state.instance.emoji.filter(emoji => - emoji.displayText.toLowerCase().includes(filterWordLowercase) - ) + const orderedEmojiList = [] + for (const emoji of this.$store.state.instance.emoji) { + const indexOfFilterWord = emoji.displayText.toLowerCase().indexOf( filterWordLowercase ) + if ( indexOfFilterWord > -1 ) { + orderedEmojiList.splice(indexOfFilterWord, 0, emoji) + } + } + return orderedEmojiList } return this.$store.state.instance.emoji || [] },