diff --git a/ts/components/emoji/lib.ts b/ts/components/emoji/lib.ts index 4b47f1ef9fec..22390aaad343 100644 --- a/ts/components/emoji/lib.ts +++ b/ts/components/emoji/lib.ts @@ -222,11 +222,24 @@ const fuse = new Fuse(data, { shouldSort: true, threshold: 0.2, minMatchCharLength: 1, - keys: ['short_name'], + keys: ['short_name', 'short_names'], +}); + +const fuseExactPrefix = new Fuse(data, { + shouldSort: true, + threshold: 0, // effectively a prefix search + minMatchCharLength: 2, + keys: ['short_name', 'short_names'], }); export function search(query: string, count = 0): Array { - const results = fuse.search(query.substr(0, 32)).map(result => result.item); + // when we only have 2 characters, do an exact prefix match + // to avoid matching on emoticon, like :-P + const fuseIndex = query.length === 2 ? fuseExactPrefix : fuse; + + const results = fuseIndex + .search(query.substr(0, 32)) + .map(result => result.item); if (count) { return take(results, count); diff --git a/ts/quill/emoji/completion.tsx b/ts/quill/emoji/completion.tsx index 919e4ff931f7..c32f2cb60a6b 100644 --- a/ts/quill/emoji/completion.tsx +++ b/ts/quill/emoji/completion.tsx @@ -183,7 +183,7 @@ export class EmojiCompletion { } } - if (leftTokenText.length < 3) { + if (leftTokenText.length < 2) { this.reset(); return PASS_THROUGH; }