Emoji fuzzysearching

This commit is contained in:
Max Leiter 2017-07-14 13:49:16 -07:00
parent 6823fc2c29
commit 4a56870c08

View File

@ -45,17 +45,26 @@ $(function() {
// Autocompletion Strategies // Autocompletion Strategies
const emojiSearchTerms = Object.keys(emojiMap);
const emojiStrategy = { const emojiStrategy = {
id: "emoji", id: "emoji",
match: /\B:([-+\w]*):?$/, match: /\B:([-+\w]*):?$/,
search(term, callback) { search(term, callback) {
callback(Object.keys(emojiMap).filter((name) => name.indexOf(term) === 0)); const results = fuzzy.filter(
term,
emojiSearchTerms,
{
pre: "<b>",
post: "</b>"
}
);
callback(results.map((el) => [el.string, el.original]));
}, },
template(value) { template([string, original]) {
return `<span class="emoji">${emojiMap[value]}</span> ${value}`; return `<span class="emoji">${emojiMap[original]}</span> ${string}`;
}, },
replace(value) { replace([, original]) {
return emojiMap[value]; return emojiMap[original];
}, },
index: 1 index: 1
}; };