mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-03 00:18:31 +00:00
Add setting for tab-completion matching
A recent PR changed the default behavior that was in FFZ for a few years at this point to bring it more in line with how Twitch handles its tab-completion: `Match anywhere in the emote name` This adds a new setting to select from 3 different match types.
This commit is contained in:
parent
cef58241d4
commit
303a2739dd
1 changed files with 61 additions and 29 deletions
|
@ -19,7 +19,7 @@ const localeCaseInsensitive = Intl.Collator(undefined, {sensitivity: 'accent'});
|
||||||
// Describes how an emote matches against a given input
|
// Describes how an emote matches against a given input
|
||||||
// Higher values represent a more exact match
|
// Higher values represent a more exact match
|
||||||
const NO_MATCH = 0;
|
const NO_MATCH = 0;
|
||||||
const CASE_INSENSITIVE_NON_PREFIX_MATCH = 1;
|
const MATCH_ANY = 1;
|
||||||
const NON_PREFIX_MATCH = 2;
|
const NON_PREFIX_MATCH = 2;
|
||||||
const CASE_INSENSITIVE_PREFIX_MATCH = 3;
|
const CASE_INSENSITIVE_PREFIX_MATCH = 3;
|
||||||
const EXACT_PREFIX_MATCH = 4;
|
const EXACT_PREFIX_MATCH = 4;
|
||||||
|
@ -156,6 +156,28 @@ export default class Input extends Module {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.settings.add('chat.tab-complete.matching', {
|
||||||
|
default: 1,
|
||||||
|
|
||||||
|
ui: {
|
||||||
|
path: 'Chat > Input >> Tab Completion',
|
||||||
|
title: 'Emote Matching Type',
|
||||||
|
description: '1: `ppa` would match `Kappa`\n\n' +
|
||||||
|
'2: `sip` would match `cohhSip` but not `Gossip`\n\n' +
|
||||||
|
'3: `pasta` would match `pastaThat` but not `HoldThat`',
|
||||||
|
|
||||||
|
component: 'setting-select-box',
|
||||||
|
|
||||||
|
data: [
|
||||||
|
{value: 1, title: '1: Anything (Twitch style)'},
|
||||||
|
{value: 2, title: '2: Non-Prefix (Old FFZ style)'},
|
||||||
|
{value: 3, title: '3: Exact (Case-Insensitive)'}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
changed: () => this.uncacheTabCompletion()
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
|
|
||||||
|
@ -890,7 +912,7 @@ export default class Input extends Module {
|
||||||
return NON_PREFIX_MATCH;
|
return NON_PREFIX_MATCH;
|
||||||
|
|
||||||
if (emote_lower.includes(term_lower))
|
if (emote_lower.includes(term_lower))
|
||||||
return CASE_INSENSITIVE_NON_PREFIX_MATCH;
|
return MATCH_ANY;
|
||||||
|
|
||||||
return NO_MATCH;
|
return NO_MATCH;
|
||||||
}
|
}
|
||||||
|
@ -1086,6 +1108,8 @@ export default class Input extends Module {
|
||||||
if ( inst.ffz_twitch_cache?.length !== inst.props.emotes?.length )
|
if ( inst.ffz_twitch_cache?.length !== inst.props.emotes?.length )
|
||||||
inst.ffz_twitch_cache = this.buildTwitchCache(inst.props.emotes);
|
inst.ffz_twitch_cache = this.buildTwitchCache(inst.props.emotes);
|
||||||
|
|
||||||
|
const emoteMatchingType = this.chat.context.get('chat.tab-complete.matching');
|
||||||
|
|
||||||
const emotes = inst.ffz_twitch_cache.emotes;
|
const emotes = inst.ffz_twitch_cache.emotes;
|
||||||
|
|
||||||
if ( ! emotes.length )
|
if ( ! emotes.length )
|
||||||
|
@ -1099,24 +1123,28 @@ export default class Input extends Module {
|
||||||
|
|
||||||
for(const emote of emotes) {
|
for(const emote of emotes) {
|
||||||
const match_type = inst.doesEmoteMatchTerm(emote, search);
|
const match_type = inst.doesEmoteMatchTerm(emote, search);
|
||||||
if ( match_type !== NO_MATCH ) {
|
if (match_type < emoteMatchingType)
|
||||||
const element = {
|
continue;
|
||||||
current: input,
|
|
||||||
emote,
|
|
||||||
replacement: emote.token,
|
|
||||||
element: inst.renderEmoteSuggestion(emote),
|
|
||||||
favorite: emote.favorite,
|
|
||||||
count: this.EmoteUsageCount[emote.token] || 0,
|
|
||||||
match_type
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( element.count > 0 )
|
const element = {
|
||||||
results_usage.push(element);
|
current: input,
|
||||||
else if ( match_type > NON_PREFIX_MATCH )
|
emote,
|
||||||
results_starting.push(element);
|
replacement: emote.token,
|
||||||
else
|
element: inst.renderEmoteSuggestion(emote),
|
||||||
results_other.push(element);
|
favorite: emote.favorite,
|
||||||
}
|
count: this.EmoteUsageCount[emote.token] || 0,
|
||||||
|
match_type
|
||||||
|
};
|
||||||
|
|
||||||
|
if (match_type < emoteMatchingType)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ( element.count > 0 )
|
||||||
|
results_usage.push(element);
|
||||||
|
else if ( match_type > NON_PREFIX_MATCH )
|
||||||
|
results_starting.push(element);
|
||||||
|
else
|
||||||
|
results_other.push(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
results_usage.sort((a,b) => b.count - a.count);
|
results_usage.sort((a,b) => b.count - a.count);
|
||||||
|
@ -1239,6 +1267,8 @@ export default class Input extends Module {
|
||||||
this.updateEmoteCompletion(parent, inst);
|
this.updateEmoteCompletion(parent, inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const emoteMatchingType = this.chat.context.get('chat.tab-complete.matching');
|
||||||
|
|
||||||
const user = inst._ffz_user,
|
const user = inst._ffz_user,
|
||||||
channel_id = inst._ffz_channel_id,
|
channel_id = inst._ffz_channel_id,
|
||||||
channel_login = inst._ffz_channel_login;
|
channel_login = inst._ffz_channel_login;
|
||||||
|
@ -1259,16 +1289,18 @@ export default class Input extends Module {
|
||||||
|
|
||||||
for(const emote of emotes) {
|
for(const emote of emotes) {
|
||||||
const match_type = inst.doesEmoteMatchTerm(emote, search)
|
const match_type = inst.doesEmoteMatchTerm(emote, search)
|
||||||
if ( match_type !== NO_MATCH )
|
if (match_type < emoteMatchingType)
|
||||||
results.push({
|
continue;
|
||||||
current: input,
|
|
||||||
emote,
|
results.push({
|
||||||
replacement: emote.token,
|
current: input,
|
||||||
element: inst.renderEmoteSuggestion(emote),
|
emote,
|
||||||
favorite: emote.favorite,
|
replacement: emote.token,
|
||||||
count: 0, // TODO: Count stuff?
|
element: inst.renderEmoteSuggestion(emote),
|
||||||
match_type
|
favorite: emote.favorite,
|
||||||
});
|
count: 0, // TODO: Count stuff?
|
||||||
|
match_type
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue