Skip to content

Commit

Permalink
Exact prefix for 2-char emoji search, search short_names
Browse files Browse the repository at this point in the history
Co-authored-by: Alvaro <110414366+alvaro-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and alvaro-signal committed Oct 17, 2022
1 parent 28020f0 commit b2ab5c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions ts/components/emoji/lib.ts
Expand Up @@ -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<EmojiData> {
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);
Expand Down
2 changes: 1 addition & 1 deletion ts/quill/emoji/completion.tsx
Expand Up @@ -183,7 +183,7 @@ export class EmojiCompletion {
}
}

if (leftTokenText.length < 3) {
if (leftTokenText.length < 2) {
this.reset();
return PASS_THROUGH;
}
Expand Down

0 comments on commit b2ab5c4

Please sign in to comment.