Merge pull request #4391 from matrix-org/t3chguy/sort_emoji_by_shortcodes

Sort emoji by shortcodes for autocomplete primarily for :-1 and :+1
This commit is contained in:
Michael Telatynski 2020-04-14 13:17:26 +01:00 committed by GitHub
commit 3aa338f3a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -100,6 +100,8 @@ export default class EmojiProvider extends AutocompleteProvider {
// then sort by score (Infinity if matchedString not in shortname) // then sort by score (Infinity if matchedString not in shortname)
sorters.push((c) => score(matchedString, c.shortname)); sorters.push((c) => score(matchedString, c.shortname));
// then sort by max score of all shortcodes, trim off the `:`
sorters.push((c) => Math.min(...c.emoji.shortcodes.map(s => score(matchedString.substring(1), s))));
// If the matchedString is not empty, sort by length of shortname. Example: // If the matchedString is not empty, sort by length of shortname. Example:
// matchedString = ":bookmark" // matchedString = ":bookmark"
// completions = [":bookmark:", ":bookmark_tabs:", ...] // completions = [":bookmark:", ":bookmark_tabs:", ...]