diff --git a/ts/components/fun/FunEmojiLocalizationProvider.tsx b/ts/components/fun/FunEmojiLocalizationProvider.tsx index 343ca380b2f..605281b6053 100644 --- a/ts/components/fun/FunEmojiLocalizationProvider.tsx +++ b/ts/components/fun/FunEmojiLocalizationProvider.tsx @@ -130,9 +130,10 @@ function useFunEmojiSearchIndex( localeEmojiList: LocaleEmojiListType | null ): FunEmojiSearchIndex { const funEmojiSearchIndex = useMemo(() => { + const defaultSearchIndex = getEmojiDefaultEnglishSearchIndex(); return localeEmojiList != null - ? createFunEmojiSearchIndex(localeEmojiList) - : getEmojiDefaultEnglishSearchIndex(); + ? createFunEmojiSearchIndex(localeEmojiList, defaultSearchIndex) + : defaultSearchIndex; }, [localeEmojiList]); return funEmojiSearchIndex; } @@ -141,9 +142,10 @@ function useFunEmojiLocalizerIndex( localeEmojiList: LocaleEmojiListType | null ): FunEmojiLocalizerIndex { const funEmojiLocalizerIndex = useMemo(() => { + const defaultSearchIndex = getEmojiDefaultEnglishLocalizerIndex(); return localeEmojiList != null - ? createFunEmojiLocalizerIndex(localeEmojiList) - : getEmojiDefaultEnglishLocalizerIndex(); + ? createFunEmojiLocalizerIndex(localeEmojiList, defaultSearchIndex) + : defaultSearchIndex; }, [localeEmojiList]); return funEmojiLocalizerIndex; } diff --git a/ts/components/fun/useFunEmojiLocalizer.tsx b/ts/components/fun/useFunEmojiLocalizer.tsx index 6345ab3b749..131e57b4d15 100644 --- a/ts/components/fun/useFunEmojiLocalizer.tsx +++ b/ts/components/fun/useFunEmojiLocalizer.tsx @@ -23,7 +23,8 @@ export type FunEmojiLocalizer = Readonly<{ }>; export function createFunEmojiLocalizerIndex( - localeEmojiList: LocaleEmojiListType + localeEmojiList: LocaleEmojiListType, + defaultLocalizerIndex?: FunEmojiLocalizerIndex ): FunEmojiLocalizerIndex { const parentKeyToLocaleShortName = new Map(); const localeShortNameToParentKey = new Map(); @@ -37,10 +38,25 @@ export function createFunEmojiLocalizerIndex( const variantKey = getEmojiVariantKeyByValue(entry.emoji); const parentKey = getEmojiParentKeyByVariantKey(variantKey); const localizedShortName = entry.tags.at(0) ?? entry.shortName; + parentKeyToLocaleShortName.set(parentKey, localizedShortName); localeShortNameToParentKey.set(localizedShortName, parentKey); } + if (defaultLocalizerIndex != null) { + for (const [ + parentKey, + defaultShortName, + ] of defaultLocalizerIndex.parentKeyToLocaleShortName) { + if (parentKeyToLocaleShortName.has(parentKey)) { + continue; + } + + parentKeyToLocaleShortName.set(parentKey, defaultShortName); + localeShortNameToParentKey.set(defaultShortName, parentKey); + } + } + return { parentKeyToLocaleShortName, localeShortNameToParentKey }; } diff --git a/ts/components/fun/useFunEmojiSearch.tsx b/ts/components/fun/useFunEmojiSearch.tsx index 8b129110614..850cfc9734e 100644 --- a/ts/components/fun/useFunEmojiSearch.tsx +++ b/ts/components/fun/useFunEmojiSearch.tsx @@ -37,10 +37,13 @@ export type FunEmojiSearch = ( ) => ReadonlyArray; export function createFunEmojiSearchIndex( - localeEmojiList: LocaleEmojiListType + localeEmojiList: LocaleEmojiListType, + defaultSearchIndex: ReadonlyArray = [] ): FunEmojiSearchIndex { const results: Array = []; + const localizedKeys = new Set(); + for (const localeEmoji of localeEmojiList) { if (!isEmojiParentValue(localeEmoji.emoji)) { // Skipping unknown emoji, most likely apple doesn't support it @@ -54,6 +57,7 @@ export function createFunEmojiSearchIndex( const parentKey = getEmojiParentKeyByValue(localeEmoji.emoji); const emoji = getEmojiParentByKey(parentKey); + localizedKeys.add(parentKey); results.push({ key: parentKey, rank: localeEmoji.rank, @@ -66,6 +70,12 @@ export function createFunEmojiSearchIndex( }); } + for (const defaultEntry of defaultSearchIndex) { + if (!localizedKeys.has(defaultEntry.key)) { + results.push(defaultEntry); + } + } + return results; }