improved algorithm, possibly speed too
This commit is contained in:
parent
f1e1f20a8d
commit
cff202241b
|
@ -11,14 +11,17 @@ const filterByKeyword = (list, keyword = '') => {
|
|||
if (keyword === '') return list
|
||||
|
||||
const keywordLowercase = keyword.toLowerCase()
|
||||
const orderedEmojiList = []
|
||||
let orderedEmojiList = []
|
||||
for (const emoji of list) {
|
||||
const indexOfKeyword = emoji.displayText.toLowerCase().indexOf(keywordLowercase)
|
||||
if (indexOfKeyword > -1) {
|
||||
orderedEmojiList.splice(indexOfKeyword, 0, emoji)
|
||||
if (!Array.isArray(orderedEmojiList[keywordLowercase])) {
|
||||
orderedEmojiList[keywordLowercase] = []
|
||||
}
|
||||
orderedEmojiList[keywordLowercase].push(emoji)
|
||||
}
|
||||
}
|
||||
return orderedEmojiList
|
||||
return orderedEmojiList.flat()
|
||||
}
|
||||
|
||||
const EmojiPicker = {
|
||||
|
|
|
@ -29,14 +29,17 @@ const ReactButton = {
|
|||
emojis () {
|
||||
if (this.filterWord !== '') {
|
||||
const filterWordLowercase = this.filterWord.toLowerCase()
|
||||
const orderedEmojiList = []
|
||||
let 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)
|
||||
if (!Array.isArray(orderedEmojiList[indexOfFilterWord])) {
|
||||
orderedEmojiList[indexOfFilterWord] = []
|
||||
}
|
||||
orderedEmojiList[indexOfFilterWord].push(emoji)
|
||||
}
|
||||
}
|
||||
return orderedEmojiList
|
||||
return orderedEmojiList.flat()
|
||||
}
|
||||
return this.$store.state.instance.emoji || []
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue