fix(workspaces): use the emojibase shortcode preset for emoji suggestions (#11888)

Swap the worktree-name emoji picker from emojibase-data's `github` shortcode preset to `emojibase`, which carries both `flag_kr` and `south_korea` style flag names, and drop the hand-maintained `kr` entry that patched around the gap. Filter skin-tone aliases so they neither crowd the suggestion list nor clobber base-emoji branch names.

Search now matches anywhere in the shortcode, ranked exact > prefix > word-start > substring, so `:korea` surfaces both Koreas.

Emoji-derived branch names now prefer spelled-out aliases: flags use country names (japan, germany, south-korea) and cryptic stubs are skipped (thumbsdown over no, victory over v).
This commit is contained in:
Neil
2026-08-01 00:40:47 -07:00
committed by GitHub
parent 96c954f3be
commit 340faaa839
5 changed files with 86 additions and 35 deletions
@@ -11,8 +11,14 @@ describe('workspace emoji shortcodes', () => {
expect(searchWorkspaceEmojiShortcodes('wink', 1)).toEqual([{ emoji: '😉', shortcode: 'wink' }])
})
it('finds the Korean flag by kr shortcode', () => {
expect(searchWorkspaceEmojiShortcodes('kr', 1)).toEqual([{ emoji: '🇰🇷', shortcode: 'kr' }])
it('finds flags by country name and by ISO code fragment', () => {
expect(searchWorkspaceEmojiShortcodes('south_korea', 1)).toEqual([
{ emoji: '🇰🇷', shortcode: 'south_korea' }
])
expect(searchWorkspaceEmojiShortcodes('kr', 1)).toEqual([{ emoji: '🇰🇷', shortcode: 'flag_kr' }])
expect(searchWorkspaceEmojiShortcodes('germany', 1)).toEqual([
{ emoji: '🇩🇪', shortcode: 'germany' }
])
})
it('ranks an exact shortcode before longer aliases', () => {
@@ -21,6 +27,23 @@ describe('workspace emoji shortcodes', () => {
})
})
it('matches inside a shortcode, ranking word starts above incidental substrings', () => {
expect(searchWorkspaceEmojiShortcodes('korea', 2)).toEqual([
{ emoji: '🇰🇵', shortcode: 'north_korea' },
{ emoji: '🇰🇷', shortcode: 'south_korea' }
])
expect(
searchWorkspaceEmojiShortcodes('kr', 3).map((suggestion) => suggestion.shortcode)
).toEqual(['flag_kr', 'ukraine', 'cockroach'])
})
it('omits skin-tone aliases from suggestions', () => {
expect(searchWorkspaceEmojiShortcodes('wave')).toEqual([
{ emoji: '👋', shortcode: 'wave' },
{ emoji: '🌊', shortcode: 'water_wave' }
])
})
it('deduplicates aliases that resolve to the same emoji', () => {
const suggestions = searchWorkspaceEmojiShortcodes('wink')
expect(new Set(suggestions.map((suggestion) => suggestion.emoji)).size).toBe(suggestions.length)
@@ -43,8 +66,8 @@ describe('workspace emoji shortcodes', () => {
})
})
it('replaces the completed kr shortcode', () => {
expect(replaceCompletedWorkspaceEmojiShortcode(':kr:', 4)).toEqual({
it('replaces a completed flag shortcode', () => {
expect(replaceCompletedWorkspaceEmojiShortcode(':flag_kr:', 9)).toEqual({
value: '🇰🇷',
cursor: 4
})
@@ -16,19 +16,24 @@ export type WorkspaceEmojiReplacement = {
value: string
}
const WORKSPACE_EMOJI_SHORTCODE_ADDITIONS: readonly WorkspaceEmojiSuggestion[] = [
{ emoji: '🇰🇷', shortcode: 'kr' }
]
const SHORTCODE_ENTRIES = [
...STANDARD_EMOJI_SHORTCODE_ENTRIES,
...WORKSPACE_EMOJI_SHORTCODE_ADDITIONS
]
const EXACT_SHORTCODE = new Map(
SHORTCODE_ENTRIES.map(({ emoji, shortcode }) => [shortcode, { emoji, shortcode }])
STANDARD_EMOJI_SHORTCODE_ENTRIES.map(({ emoji, shortcode }) => [shortcode, { emoji, shortcode }])
)
// Lower tiers rank first, so `korea` surfaces `south_korea` above `dishwasher`-style incidental hits.
const MATCH_TIER = { exact: 0, prefix: 1, wordStart: 2, substring: 3 } as const
function matchTier(shortcode: string, query: string): number | null {
const index = shortcode.indexOf(query)
if (index < 0) {
return null
}
if (index === 0) {
return shortcode.length === query.length ? MATCH_TIER.exact : MATCH_TIER.prefix
}
return /[_-]/.test(shortcode[index - 1]) ? MATCH_TIER.wordStart : MATCH_TIER.substring
}
export function searchWorkspaceEmojiShortcodes(
query: string,
limit = 8
@@ -38,11 +43,12 @@ export function searchWorkspaceEmojiShortcodes(
return []
}
const matches = SHORTCODE_ENTRIES.filter(({ shortcode }) =>
shortcode.startsWith(normalizedQuery)
).sort(
const matches = STANDARD_EMOJI_SHORTCODE_ENTRIES.flatMap((entry) => {
const tier = matchTier(entry.shortcode, normalizedQuery)
return tier === null ? [] : [{ ...entry, tier }]
}).sort(
(left, right) =>
Number(right.shortcode === normalizedQuery) - Number(left.shortcode === normalizedQuery) ||
left.tier - right.tier ||
left.shortcode.length - right.shortcode.length ||
left.shortcode.localeCompare(right.shortcode)
)