client: Sort emojis by query similarity in fuzzy picker #156

Merged
norm merged 6 commits from Michcio/FoundKey-0x7f:tostis-emojosort into main 2022-09-19 14:43:13 +00:00
Showing only changes of commit 0e174a3f9d - Show all commits

View file

@ -150,7 +150,7 @@ function emojiSearch<Type extends foundkey.entities.CustomEmoji|UnicodeEmojiDef>
const joinq = query.replace(/\s+/g, '');
const distance = (str: string): number => rodistance(joinq, str);
const mindistance = (strs: string[]): number => Math.min(...strs.map(distance));
const distinguisher = (emoji: Type): string => 'char' in emoji ? emoji.char : emoji.name;
const distinguisher = (emoji: Type): string => 'char' in emoji ? emoji.char : emoji.id;
matches.forEach(emoji => distances[distinguisher(emoji)] = Math.min(distance(emoji.name), mindistance(aliases(emoji))));
Michcio marked this conversation as resolved Outdated
Outdated
Review

Is there a reason forEach is used instead of for (const emoji of matches)?

Is there a reason `forEach` is used instead of `for (const emoji of matches)`?

No, it just wasn't an error. I too prefer for (...).

No, it just wasn't an error. I too prefer `for (...)`.
// sort by distance from query