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
+31 -11
View File
@@ -1,25 +1,45 @@
import emojiShortcodes from 'emojibase-data/en/shortcodes/github.json'
import emojiShortcodes from 'emojibase-data/en/shortcodes/emojibase.json'
export type StandardEmojiShortcodeEntry = {
emoji: string
shortcode: string
}
// Skin-tone aliases (`wave_tone3`) are ~40% of the dataset and would drown the suggestion list.
const SKIN_TONE_SHORTCODE = /_tone\d(?:-\d)?$/
const CATALOG = Object.entries(emojiShortcodes).flatMap(([hexcode, value]) => {
const shortcodes = (typeof value === 'string' ? [value] : value).filter(
(shortcode) => !SKIN_TONE_SHORTCODE.test(shortcode)
)
return shortcodes.length > 0 ? [{ emoji: hexcodeToEmoji(hexcode), shortcodes }] : []
})
export const STANDARD_EMOJI_SHORTCODE_ENTRIES: readonly StandardEmojiShortcodeEntry[] =
Object.entries(emojiShortcodes).flatMap(([hexcode, value]) => {
const shortcodes = typeof value === 'string' ? [value] : value
const emoji = hexcodeToEmoji(hexcode)
return shortcodes.map((shortcode) => ({ emoji, shortcode }))
})
CATALOG.flatMap(({ emoji, shortcodes }) => shortcodes.map((shortcode) => ({ emoji, shortcode })))
const PRIMARY_SHORTCODE_BY_EMOJI = new Map(
Object.entries(emojiShortcodes).map(([hexcode, value]) => {
const shortcodes = typeof value === 'string' ? [value] : value
const shortcode = shortcodes.find((candidate) => /^[a-z]/i.test(candidate)) ?? shortcodes[0]
return [normalizeEmojiLookup(hexcodeToEmoji(hexcode)), shortcode]
})
CATALOG.map(({ emoji, shortcodes }) => [
normalizeEmojiLookup(emoji),
primaryShortcode(shortcodes)
])
)
/**
* Pick the alias that reads best as a branch or directory name: skip `+1`/`-1` so the name
* starts with a letter, then cryptic stubs (👎 `no`, ✌ `v`) and the `flag_xx` namespacing
* prefix, both of which have a spelled-out alias (`thumbsdown`, `victory`, `germany`).
*/
function primaryShortcode(shortcodes: readonly string[]): string {
const named = shortcodes.filter((candidate) => /^[a-z]/i.test(candidate))
return (
named.find((candidate) => candidate.length >= 3 && !candidate.startsWith('flag_')) ??
named.find((candidate) => candidate.length >= 3) ??
named[0] ??
shortcodes[0]
)
}
const EMOJI_SEGMENTER = new Intl.Segmenter('en', { granularity: 'grapheme' })
export function replaceKnownEmojiWithShortcodes(input: string): string {