From 4a56870c08ee426b20431fe49ecca2a73ef25ae0 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Fri, 14 Jul 2017 13:49:16 -0700 Subject: [PATCH] Emoji fuzzysearching --- client/js/lounge.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index b67bc4eb..e7128eeb 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -45,17 +45,26 @@ $(function() { // Autocompletion Strategies + const emojiSearchTerms = Object.keys(emojiMap); const emojiStrategy = { id: "emoji", match: /\B:([-+\w]*):?$/, search(term, callback) { - callback(Object.keys(emojiMap).filter((name) => name.indexOf(term) === 0)); + const results = fuzzy.filter( + term, + emojiSearchTerms, + { + pre: "", + post: "" + } + ); + callback(results.map((el) => [el.string, el.original])); }, - template(value) { - return `${emojiMap[value]} ${value}`; + template([string, original]) { + return `${emojiMap[original]} ${string}`; }, - replace(value) { - return emojiMap[value]; + replace([, original]) { + return emojiMap[original]; }, index: 1 };