mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-02 16:08:31 +00:00
Adds toggle for new emote sorting behavior
This commit is contained in:
parent
c4301a234d
commit
0ea064ad68
1 changed files with 39 additions and 24 deletions
|
@ -128,6 +128,15 @@ export default class Input extends Module {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.settings.add('chat.tab-complete.prioritize-prefix-matches', {
|
||||||
|
default: false,
|
||||||
|
ui: {
|
||||||
|
path: 'Chat > Input >> Tab Completion',
|
||||||
|
title: 'Prioritize emotes that start with user input.',
|
||||||
|
component: 'setting-check-box'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
|
|
||||||
|
@ -664,6 +673,7 @@ export default class Input extends Module {
|
||||||
sortEmotes(emotes) {
|
sortEmotes(emotes) {
|
||||||
const preferFavorites = this.chat.context.get('chat.tab-complete.prioritize-favorites');
|
const preferFavorites = this.chat.context.get('chat.tab-complete.prioritize-favorites');
|
||||||
const canBeTriggeredByTab = this.chat.context.get('chat.tab-complete.emotes-without-colon');
|
const canBeTriggeredByTab = this.chat.context.get('chat.tab-complete.emotes-without-colon');
|
||||||
|
const prioritizePrefixMatches = this.chat.context.get('chat.tab-complete.prioritize-prefix-matches');
|
||||||
|
|
||||||
return emotes.sort((a, b) => {
|
return emotes.sort((a, b) => {
|
||||||
const aStr = a.matched || a.replacement;
|
const aStr = a.matched || a.replacement;
|
||||||
|
@ -673,32 +683,37 @@ export default class Input extends Module {
|
||||||
if (preferFavorites && (a.favorite ^ b.favorite))
|
if (preferFavorites && (a.favorite ^ b.favorite))
|
||||||
return 0 - a.favorite + b.favorite;
|
return 0 - a.favorite + b.favorite;
|
||||||
|
|
||||||
// Prefer emoji over emotes if tab-complete is enabled, disprefer them otherwise
|
if (prioritizePrefixMatches) {
|
||||||
const aIsEmoji = !!a.matched;
|
// Prefer emoji over emotes if tab-complete is enabled, disprefer them otherwise
|
||||||
const bIsEmoji = !!b.matched;
|
const aIsEmoji = !!a.matched;
|
||||||
if (aIsEmoji ^ bIsEmoji) {
|
const bIsEmoji = !!b.matched;
|
||||||
if (canBeTriggeredByTab) return 0 - aIsEmoji + bIsEmoji;
|
if (aIsEmoji ^ bIsEmoji) {
|
||||||
else return 0 - bIsEmoji + aIsEmoji;
|
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);
|
||||||
|
if (aStartsWithInput && bStartsWithInput)
|
||||||
|
return locale.compare(aStr, bStr);
|
||||||
|
else if (aStartsWithInput) return -1;
|
||||||
|
else if (bStartsWithInput) return 1;
|
||||||
|
|
||||||
|
// Else prefer case-insensitive prefix matches
|
||||||
|
const aStartsWithInputCI = (a.match_type === CASE_INSENSITIVE_PREFIX_MATCH);
|
||||||
|
const bStartsWithInputCI = (b.match_type === CASE_INSENSITIVE_PREFIX_MATCH);
|
||||||
|
if (aStartsWithInputCI && bStartsWithInputCI)
|
||||||
|
return localeCaseInsensitive.compare(aStr, bStr);
|
||||||
|
else if (aStartsWithInputCI) return -1;
|
||||||
|
else if (bStartsWithInputCI) return 1;
|
||||||
|
|
||||||
|
// Else alphabetize
|
||||||
|
return locale.compare(aStr, bStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prefer case-sensitive prefix matches
|
// Keep unsorted order for non-favorite items if prefix matching is not enabled.
|
||||||
const aStartsWithInput = (a.match_type === EXACT_PREFIX_MATCH);
|
return 0;
|
||||||
const bStartsWithInput = (b.match_type === EXACT_PREFIX_MATCH);
|
|
||||||
if (aStartsWithInput && bStartsWithInput)
|
|
||||||
return locale.compare(aStr, bStr);
|
|
||||||
else if (aStartsWithInput) return -1;
|
|
||||||
else if (bStartsWithInput) return 1;
|
|
||||||
|
|
||||||
// Else prefer case-insensitive prefix matches
|
|
||||||
const aStartsWithInputCI = (a.match_type === CASE_INSENSITIVE_PREFIX_MATCH);
|
|
||||||
const bStartsWithInputCI = (b.match_type === CASE_INSENSITIVE_PREFIX_MATCH);
|
|
||||||
if (aStartsWithInputCI && bStartsWithInputCI)
|
|
||||||
return localeCaseInsensitive.compare(aStr, bStr);
|
|
||||||
else if (aStartsWithInputCI) return -1;
|
|
||||||
else if (bStartsWithInputCI) return 1;
|
|
||||||
|
|
||||||
// Else alphabetize
|
|
||||||
return locale.compare(aStr, bStr);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue