refactor(widgets): collapse the duplicated Nerd Font toggle helpers - #544
Merged
Merged
Conversation
VimMode, SandboxStatus, RemoteControlStatus, VoiceStatus and CompactionCounter each carried their own copy of the same four helpers. The first four were byte-identical apart from the format type name; CompactionCounter's differed only by inlining its predicate. Net -163 lines. shared/metadata.ts gains isNerdFontEnabled, setNerdFontFormat and toggleNerdFont, each taking a NerdFontFormats config as a trailing argument, which matches how symbol-override.tsx threads SymbolSlot. Each widget keeps only its own canUseNerdFont predicate, the part that is genuinely per-widget. CompactionCounter gains one as a named function, which also covers the copy inlined in its keybind gate. toggleMetadataFlag is deliberately not reused here: it writes nerdFont:'false', while every one of these widgets deletes the key and collapses empty metadata to undefined. SandboxStatus and VoiceStatus also shared a byte-identical config cwd resolver; both now call resolveClaudeConfigCwd next to the settings layering it feeds.
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.
Five widgets each carried their own copy of the same four Nerd Font toggle
helpers:
VimMode.ts,SandboxStatus.ts,RemoteControlStatus.ts,VoiceStatus.tsandCompactionCounter.ts. The first four are byte-identicalonce the format type name is normalized; CompactionCounter's differ only by
inlining its predicate. Net -163 lines.
Pure dedup, no behavior change.
shared/metadata.tsgainsisNerdFontEnabled,setNerdFontFormatandtoggleNerdFont, each taking aNerdFontFormatsconfig as a trailing argument.That module already owned
removeMetadataKeys, whichremoveNerdFontreduces toa one-liner over, and CompactionCounter was already importing from it for its
hide flag while hand-rolling these lower in the same file.
Config-object-per-call rather than a factory, since it matches how
symbol-override.tsxthreadsSymbolSlotand nothing inshared/uses afactory. It also keeps
canUseNerdFontlazy, which matters because two of thepredicates read
item.rawValue.Each widget keeps only its own
canUseNerdFont, which is the genuinelyper-widget half:
icon-dash-letter,icon-letteroriconglyphicon, oricon-textoutside raw value modeCompactionCounter had no such function; it inlined that predicate in three
places, including its keybind gate. It gets one as a named function, which
collapses all three.
Two things worth flagging:
toggleMetadataFlaglooks like it should servetoggleNerdFontand does not.It writes
nerdFont: 'false', while all five widgets delete the key andcollapse empty metadata to
undefined. Reusing it would write junk into everyuser's settings.json.
removeMetadataKeysis the exact match and is what thisuses.
SandboxStatusandVoiceStatusalso carried a byte-identical config cwdresolver. Both now call
resolveClaudeConfigCwd, which lives inclaude-settings.tsnext to the settings layering it feeds.No test file is touched, which is the point: the existing suites pin the behavior
and still pass unchanged.
Tested:
bun run lintclean;bun test1866 pass, plus theglobal-command-resolutionfailuremainalready has on this host and one hitof the flaky
fetchUsageDatacase.