From 3a0e1aeeaf75ce74f3b837ae720d21aa1ef8714c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 11 Apr 2020 18:09:28 +0100 Subject: [PATCH 1/2] Sort emoji by shortcodes for autocomplete so that :-1 and :+1 first results are correct Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/autocomplete/EmojiProvider.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/autocomplete/EmojiProvider.js b/src/autocomplete/EmojiProvider.js index 9373ed662e..76058b42b0 100644 --- a/src/autocomplete/EmojiProvider.js +++ b/src/autocomplete/EmojiProvider.js @@ -100,6 +100,10 @@ export default class EmojiProvider extends AutocompleteProvider { // then sort by score (Infinity if matchedString not in shortname) sorters.push((c) => score(matchedString, c.shortname)); + // then sort by max score of all shortcodes, trim off the `:` + sorters.push((c) => { + return Math.min.apply(null, c.emoji.shortcodes.map(s => score(matchedString.substring(1), s))); + }); // If the matchedString is not empty, sort by length of shortname. Example: // matchedString = ":bookmark" // completions = [":bookmark:", ":bookmark_tabs:", ...] From e114effcfad25efe3a2e16faf3a26a0c21ef82ff Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 14 Apr 2020 13:07:44 +0100 Subject: [PATCH 2/2] make code more readable as per pr suggestion Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/autocomplete/EmojiProvider.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/autocomplete/EmojiProvider.js b/src/autocomplete/EmojiProvider.js index 76058b42b0..670776644e 100644 --- a/src/autocomplete/EmojiProvider.js +++ b/src/autocomplete/EmojiProvider.js @@ -101,9 +101,7 @@ export default class EmojiProvider extends AutocompleteProvider { // then sort by score (Infinity if matchedString not in shortname) sorters.push((c) => score(matchedString, c.shortname)); // then sort by max score of all shortcodes, trim off the `:` - sorters.push((c) => { - return Math.min.apply(null, c.emoji.shortcodes.map(s => score(matchedString.substring(1), s))); - }); + 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: // matchedString = ":bookmark" // completions = [":bookmark:", ":bookmark_tabs:", ...]