Exact prefix for 2-char emoji search, search short_names

Co-authored-by: Alvaro <110414366+alvaro-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2022-10-17 10:39:37 -07:00 committed by GitHub
parent 28020f00d2
commit b2ab5c4bc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -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);

View File

@ -183,7 +183,7 @@ export class EmojiCompletion {
}
}
if (leftTokenText.length < 3) {
if (leftTokenText.length < 2) {
this.reset();
return PASS_THROUGH;
}