Repository navigation
vim: the shared status line follows the preference, not a live observer - #657
Conversation
498e82c to
ffe53d0
Compare
VimStatusLine (ContentView.swift) renders from VimMode.Status.shared,
and the only thing that cleared that singleton was VimMode.deactivate()
— reached through EditorPreferences.observeApplying(to:), an
observation held weakly by a live editor coordinator that bails when
the token or text view is gone. So switching Vim off from the menu
(⌃⌘V) or the command palette with no editor alive, or while one was
being torn down, never ran deactivate(): Status.shared stayed at
"-- NORMAL --" for the rest of the process and the next editor opened
showed a phantom status row with Vim off.
The preference now pushes the change itself: the vimKeybindings setter
calls VimMode.preferenceDidChange(to:), which switches off the views
that follow the preference and re-derives the status line. VimMode
keeps a weak registry of the modes that are actually on, so the
singleton is re-derived from what is left rather than blanked blindly.
Views that pin Vim per-view through vimEnabledOverride are deliberately
untouched and keep owning the status line: a render gate on the
preference inside VimStatusLine would have been the obvious fix and
would have broken every test that uses the override.
This is also the cause of three red CI tests in
VimStatusLinePlacementTests: testCommandLineSharesTheSameRow runs first
alphabetically and its tearDown sets the preference false, then
destroys the window immediately — the scheduled Task { @mainactor }
lost the race with coordinator teardown on a loaded runner, leaving the
row visible for every later test ("lost 0.0 pt", XCTAssertNil failed:
"-- NORMAL --"). The clear is now synchronous on the setter, so there
is no race to lose. Those tests are unchanged: the product was wrong.
Implementation-Agent: claude-fable-5 (Claude Code subagent)
Commit-Executor: claude-fable-5 (Claude Code subagent)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
ffe53d0 to
8395167
Compare
|
Rebased onto current Vim surface on the rebased head, run serially: That includes the 4 Full-suite pass count is re-running serially. The earlier full-gate numbers from this machine are not usable: several agents were running suites concurrently (load average peaked at 196, wall time 1106s against a normal ~270s) and the failures were load artifacts — perf assertions, |
Independent of the dispatch-policy stack — this is a lifecycle fix, not a keymap change. Rebased onto current
main(post-#654). Fixes 3 red tests on main.The bug
VimMode.Status.sharedcan go permanently stale, showing a phantom-- NORMAL --row while Vim is off.VimStatusLine(ContentView.swift:809) renders purely fromVimMode.Status.shared.indicator. Its doc comment claims "while the preference is offindicatoris nil" — nothing enforced that.VimMode.deactivate(), reached viaEditorPreferences.apply(to:)→applyVimPreference, through awithObservationTrackingtoken held weakly by a live text view's coordinator (EditorPreferences.swift:494); itsonChangefires into aTask { @MainActor }that bails if the token or textView is gone.deactivate()never runs and the singleton stays at-- NORMAL --globally.User-visible, not just a test artifact: toggle Vim off from the menu (⌃⌘V,
FlashTeXMacApp.swift:167) or the command palette with no editor window alive, and the next editor you open shows a phantom-- NORMAL --status row with Vim off.The fix
The preference pushes the change itself instead of waiting to be observed: the
vimKeybindingssetter callsVimMode.preferenceDidChange(to:).VimModekeeps a weak registry of every live mode (NSHashTable.weakObjects(), registered atinit), each with its ownisOnflag.preferenceDidChangeapplies the preference to every view that follows it in both directions, thenrefreshSharedStatus()re-derives the status line from whichever modes are still on — so a second editor with Vim on keeps its row, and only "nothing is on" clears it.The caveat that makes the obvious fix wrong (and is handled):
vimEnabledOverridepins Vim per-view independently of the global preference, so the clear lives on the preference transition, never as a render gate inVimStatusLine. Gating the view on the preference would break every test that uses the override — there is an explicit regression test for exactly that.Why CI was red, and why those tests are not touched
VimStatusLinePlacementTests.testCommandLineSharesTheSameRowruns first alphabetically, passes, and itstearDownsets the preference false then destroys the window immediately — the scheduledTask { @MainActor }loses the race against coordinator teardown. Every later test then starts with the row already showing → "lost 0.0 pt" andXCTAssertNil failed: "-- NORMAL --"intestStatusLineIsTheEditorsBottomRowBesideThePreview,…WithTheProblemsPanelOpenandtestVimOffTakesNoSpaceAtAll. On a fast Mac the Task wins; on a loaded CI runner it loses. The clear is now synchronous on the setter, so there is no race to lose.Test justification (standing owner requirement): the three failing
VimStatusLinePlacementTestsare unchanged — the product was wrong, not the tests. Added 3 regression tests toVimModeTests.swift: preference-off with no live editor clears the singleton; a per-view override keeps its status line when the preference goes off (this one guards against the wrong fix); and the clear is synchronous rather than on a later run-loop turn. One existing line changed:tearDown'stv.vimEnabledOverride→tv?.vimEnabledOverride, because the no-live-editor test releases the view on purpose.Rebase note: resolving onto post-#654 main required a union merge in
VimModeTests.swift(both commits append tests at the end of the class, and the conflict boundary cut through the last function of each side). Both blocks are kept; brace balance and the seam were checked by hand.Mac gate result on the rebased head posted as a comment.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu