aboutsummaryrefslogtreecommitdiff
path: root/src/components/emoji_input/suggestor.js
diff options
context:
space:
mode:
authorShpuld Shpuldson <shp@cock.li>2020-06-18 16:47:37 +0300
committerShpuld Shpuldson <shp@cock.li>2020-06-18 16:47:37 +0300
commit8a9654b511268338d46f351da43a6bd85fbcb972 (patch)
tree66d477ba0dc307e1074b5025933918da5ef31478 /src/components/emoji_input/suggestor.js
parent6d2befa452d6b42e47968f382a7ff62d4eb0d9b9 (diff)
parentebf4321e645a34a40c00b0884546e9da86361952 (diff)
Merge branch 'develop' into features/favicons
Diffstat (limited to 'src/components/emoji_input/suggestor.js')
-rw-r--r--src/components/emoji_input/suggestor.js24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/components/emoji_input/suggestor.js b/src/components/emoji_input/suggestor.js
index aec5c39d..15a71eff 100644
--- a/src/components/emoji_input/suggestor.js
+++ b/src/components/emoji_input/suggestor.js
@@ -29,17 +29,29 @@ export default data => input => {
export const suggestEmoji = emojis => input => {
const noPrefix = input.toLowerCase().substr(1)
return emojis
- .filter(({ displayText }) => displayText.toLowerCase().startsWith(noPrefix))
+ .filter(({ displayText }) => displayText.toLowerCase().match(noPrefix))
.sort((a, b) => {
let aScore = 0
let bScore = 0
- // Make custom emojis a priority
- aScore += a.imageUrl ? 10 : 0
- bScore += b.imageUrl ? 10 : 0
+ // An exact match always wins
+ aScore += a.displayText.toLowerCase() === noPrefix ? 200 : 0
+ bScore += b.displayText.toLowerCase() === noPrefix ? 200 : 0
- // Sort alphabetically
- const alphabetically = a.displayText > b.displayText ? 1 : -1
+ // Prioritize custom emoji a lot
+ aScore += a.imageUrl ? 100 : 0
+ bScore += b.imageUrl ? 100 : 0
+
+ // Prioritize prefix matches somewhat
+ aScore += a.displayText.toLowerCase().startsWith(noPrefix) ? 10 : 0
+ bScore += b.displayText.toLowerCase().startsWith(noPrefix) ? 10 : 0
+
+ // Sort by length
+ aScore -= a.displayText.length
+ bScore -= b.displayText.length
+
+ // Break ties alphabetically
+ const alphabetically = a.displayText > b.displayText ? 0.5 : -0.5
return bScore - aScore + alphabetically
})