Fix emoji search crash, show all supported emoji
This commit is contained in:
parent
a815d81c6c
commit
43a26fb017
2 changed files with 21 additions and 4 deletions
|
@ -237,7 +237,24 @@ export function createSearch(localeEmoji: SearchEmojiListType): SearchFnType {
|
||||||
return cachedSearchFn.fn;
|
return cachedSearchFn.fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fuse = new Fuse(localeEmoji, {
|
const knownSet = new Set<string>();
|
||||||
|
|
||||||
|
const knownEmoji = localeEmoji.filter(({ shortName }) => {
|
||||||
|
knownSet.add(shortName);
|
||||||
|
return dataByShortName[shortName] != null;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const entry of data) {
|
||||||
|
if (!knownSet.has(entry.short_name)) {
|
||||||
|
knownEmoji.push({
|
||||||
|
shortName: entry.short_name,
|
||||||
|
rank: 0,
|
||||||
|
tags: entry.short_names,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fuse = new Fuse(knownEmoji, {
|
||||||
shouldSort: true,
|
shouldSort: true,
|
||||||
threshold: 0.2,
|
threshold: 0.2,
|
||||||
minMatchCharLength: 1,
|
minMatchCharLength: 1,
|
||||||
|
@ -245,7 +262,7 @@ export function createSearch(localeEmoji: SearchEmojiListType): SearchFnType {
|
||||||
includeScore: true,
|
includeScore: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const fuseExactPrefix = new Fuse(localeEmoji, {
|
const fuseExactPrefix = new Fuse(knownEmoji, {
|
||||||
shouldSort: true,
|
shouldSort: true,
|
||||||
threshold: 0, // effectively a prefix search
|
threshold: 0, // effectively a prefix search
|
||||||
minMatchCharLength: 2,
|
minMatchCharLength: 2,
|
||||||
|
@ -264,7 +281,7 @@ export function createSearch(localeEmoji: SearchEmojiListType): SearchFnType {
|
||||||
const rank = entry.item.rank || 1e9;
|
const rank = entry.item.rank || 1e9;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
score: (entry.score ?? 0) + rank / localeEmoji.length,
|
score: (entry.score ?? 0) + rank / knownEmoji.length,
|
||||||
item: entry.item,
|
item: entry.item,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -168,7 +168,7 @@ describe('emojiCompletion', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('stores the results and renders', () => {
|
it('stores the results and renders', () => {
|
||||||
assert.equal(emojiCompletion.results.length, 2);
|
assert.equal(emojiCompletion.results.length, 10);
|
||||||
assert.equal((emojiCompletion.render as sinon.SinonStub).called, true);
|
assert.equal((emojiCompletion.render as sinon.SinonStub).called, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue