From c4301a234d56af7c324e2de3baf61502b25ef2a8 Mon Sep 17 00:00:00 2001 From: cfinegan Date: Thu, 20 Jan 2022 21:03:27 -0500 Subject: [PATCH] sortEmotes now prefers or disprefers emojis based on user settings Previously, it erroneously sorted them based on the value of the emoji's codepoint sequence. --- src/sites/twitch-twilight/modules/chat/input.jsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/sites/twitch-twilight/modules/chat/input.jsx b/src/sites/twitch-twilight/modules/chat/input.jsx index 50bcc916..752934cd 100644 --- a/src/sites/twitch-twilight/modules/chat/input.jsx +++ b/src/sites/twitch-twilight/modules/chat/input.jsx @@ -663,15 +663,24 @@ export default class Input extends Module { // eslint-disable-next-line class-methods-use-this sortEmotes(emotes) { const preferFavorites = this.chat.context.get('chat.tab-complete.prioritize-favorites'); + const canBeTriggeredByTab = this.chat.context.get('chat.tab-complete.emotes-without-colon'); return emotes.sort((a, b) => { - const aStr = a.replacement; - const bStr = b.replacement; + const aStr = a.matched || a.replacement; + const bStr = b.matched || b.replacement; // Prefer favorites over non-favorites, if enabled if (preferFavorites && (a.favorite ^ b.favorite)) return 0 - a.favorite + b.favorite; + // Prefer emoji over emotes if tab-complete is enabled, disprefer them otherwise + const aIsEmoji = !!a.matched; + const bIsEmoji = !!b.matched; + if (aIsEmoji ^ bIsEmoji) { + if (canBeTriggeredByTab) return 0 - aIsEmoji + bIsEmoji; + else return 0 - bIsEmoji + aIsEmoji; + } + // Prefer case-sensitive prefix matches const aStartsWithInput = (a.match_type === EXACT_PREFIX_MATCH); const bStartsWithInput = (b.match_type === EXACT_PREFIX_MATCH);