From 08e0ea38a1d3283109daee337d4c4fb8f72bf3ef Mon Sep 17 00:00:00 2001 From: OMGparticles Date: Sat, 22 Apr 2023 21:26:42 -0700 Subject: [PATCH] - Added option to revert to old behavior which only considers matches at the start of the emote and at capitalized sections. --- .../twitch-twilight/modules/chat/input.jsx | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/sites/twitch-twilight/modules/chat/input.jsx b/src/sites/twitch-twilight/modules/chat/input.jsx index b27610c5..eb4411a3 100644 --- a/src/sites/twitch-twilight/modules/chat/input.jsx +++ b/src/sites/twitch-twilight/modules/chat/input.jsx @@ -151,6 +151,16 @@ export default class Input extends Module { } }); + this.settings.add('chat.tab-complete.prefix-and-capitals-only', { + default: false, + ui: { + path: 'Chat > Input >> Tab Completion', + title: 'Only match emotes at start or at capitalized sections.', + description: 'Will only suggest emotes if the term resides at the start of the emote, or at a capital letter.', + component: 'setting-check-box' + } + }); + // Components @@ -1030,9 +1040,12 @@ export default class Input extends Module { search = input.startsWith(':') ? input.slice(1) : input; + const only_match_starts = this.chat.context.get('chat.tab-complete.prefix-and-capitals-only'); + for(const emote of emotes) { const match_type = inst.doesEmoteMatchTerm(emote, search); - if ( match_type !== NO_MATCH ) { + const valid_match = only_match_starts ? match_type > SUBSTRING_MATCH : match_type !== NO_MATCH; + if ( valid_match ) { const element = { current: input, emote, @@ -1080,8 +1093,13 @@ export default class Input extends Module { const included = new Set; - for(const name in this.emoji.names) - if ( has_colon ? name === search : name.startsWith(search) ) { + const only_match_starts = this.chat.context.get('chat.tab-complete.prefix-and-capitals-only'); + + for(const name in this.emoji.names) { + const valid_match = has_colon && name === search || + only_match_starts && name.startsWith(search) || + ! only_match_starts && name.includes(search); + if ( valid_match ) { const emoji = this.emoji.emoji[this.emoji.names[name]], toned = emoji.variants && emoji.variants[tone], source = toned || emoji; @@ -1110,6 +1128,7 @@ export default class Input extends Module { }); } } + } return results; } @@ -1193,9 +1212,12 @@ export default class Input extends Module { const search = input.startsWith(':') ? input.slice(1) : input, results = []; + const only_match_starts = this.chat.context.get('chat.tab-complete.prefix-and-capitals-only'); + for(const emote of emotes) { - const match_type = inst.doesEmoteMatchTerm(emote, search) - if ( match_type !== NO_MATCH ) + const match_type = inst.doesEmoteMatchTerm(emote, search); + const valid_match = only_match_starts ? match_type > SUBSTRING_MATCH : match_type !== NO_MATCH; + if ( valid_match ) results.push({ current: input, emote,