feat(desktop): fuzzy emoji shortcode autocomplete#1945
Open
torstenrudolf wants to merge 1 commit into
Open
Conversation
The inline :shortcode autocomplete matched only strict substrings, and emoji-mart's own search is token-prefix based, so it can't cross the `_` separator — `pointup` never found `point_up`. Add a shared separator-insensitive matcher (emojiSearch.ts) with tiered ranking: exact > prefix > substring > subsequence. Custom emoji now rank through it, and standard-emoji results are topped up with fuzzy matches emoji-mart missed, filling only leftover slots so normal queries are unchanged. Subsequence hits rank last to keep recall gains low-noise. Scoped to the composer autocomplete; the picker popover (which routes through emoji-mart's own search) is unchanged. Signed-off-by: Torsten Rudolf <trudolf@squareup.com>
tlongwell-block
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Make the inline
:shortcodeemoji autocomplete match fuzzily, so a query that omits separators (or characters) still finds the emoji.pointupnow finds:point_up:;pntupfinds it too.Why
Two limitations stacked up:
shortcode.includes(query)— a literal substring, so the_separator blockedpointup→point_up.SearchIndex.search, which is token-prefix based: it splitspoint_upintopoint/upand matches a query as a token prefix, so the single tokenpointupmatched neither.How
New shared matcher
desktop/src/shared/lib/emojiSearch.tswith tiered, separator-insensitive ranking:Both sides are normalized by stripping
:,_,-, and whitespace. Tiers 1–3 keep normal queries ordered exactly as before; the subsequence tier only adds looser matches and always ranks last, so recall improves without noisy reordering.Wiring in
useEmojiAutocomplete.ts:The full emoji set (~1.8k) is scanned per keystroke, behind the existing 120 ms debounce — sub-millisecond, and the flat index is built once at module level.
Scope: composer autocomplete only. The emoji picker popover routes through emoji-mart's own search and is unchanged (could follow up via a patch since both surfaces share
SearchIndex).Complexity
Per candidate shortcode,
scoreShortcodeMatchtries the four tiers in order and short-circuits on the first hit. Letq= normalized query length,L= candidate shortcode length,N= number of candidates (~1.8k standard + workspace custom).q === targettarget.startsWith(q)target.indexOf(q)subsequenceSpan)Per keystroke the matcher scans all
Ncandidates, so worst case is O(N · q · L), dominated by the substring tier. SinceqandLare tiny bounded values (shortcodes are short), this is effectively a linear O(N) scan — ~1.8k short-string comparisons, sub-millisecond behind the 120 ms debounce. Ranking thekmatches adds an O(k log k) sort. Space is O(k) for the scored buffer plus the one-time O(N) flat index built at module load.Testing
emojiSearch.test.mjs, 12 cases): tier classification,pointup/pntup/ointp→point_up, ranking order, limit handling, andfuzzyStandardEmojiagainst the real dataset.pnpm typecheckandbiome checkpass on the changed files.