Repository navigation
fix(editor): keep a pinned duplicate open on close and ignore setActiveFile for a missing file - #28120
Conversation
…wner twin Closing a document also closes clean same-owner duplicate records; a record whose tab is pinned is now left open with its tab.
A stale tab or pane id could make a missing file active and persist it as the workspace's active file.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The change keeps a pinned duplicate tab open when its sibling closes and ignores setActiveFile calls for unknown files. No actionable merge risk was identified. Pre-merge checks ·
|
Samuel Vila (@SamuelAdigos) independently submitted both editor guards and regression tests in #28063 before #28120 was opened. The narrower implementation landed in #28120; this follow-up records credit for his earlier contribution. Co-authored-by: Samuel Vila <[email protected]>
ELI5
Two small guards for editor tabs:
What Changed
1. A pinned duplicate survives the close.
closeFile(since main'sc9f4cd7e27) also sweeps clean duplicate records for the same document and the same owner. It skipped dirty records and records with a draft, but not pinned ones. A pinned tab could vanish because you closed another tab for the same file.closeFilealso skips a record whose tab in that workspace is pinned. That record and its tab stay open. Other clean, unpinned duplicates are still swept as before. This is the sibling sweep insidecloseFile, not a bulk close command.2.
setActiveFileignores an id with no open file.OpenFilerecord.setActiveFilestill made it the global active file (activeFileId) when the call was scoped to the active workspace. The per-workspace entry (activeFileIdByWorktree) was already left alone, because no file supplied a workspace id.setActiveFilereturns without changing anything when no open file has that id. It does not log a warning.Production change: 6 lines, in
close-file-action.tsandopen-file-mutations.ts.Why
These are the two parts of #21124 that main does not already cover. The rest of #21124 is superseded by @nwparker's commits on main:
c9f4cd7e27"close stale duplicate documents safely". It adapts fix(editor): close duplicate document siblings #23347's sibling sweep, with exact owner and captured-provenance checks.8bd567a015"protect document backing files and complete close cleanup".31d85749b4"retain placeholders for drafts during bulk close".14bae2e172"route mirrored editor closes through their captured runtime owner".Deliberately not carried over from #21124:
Linked Issue
Fixes #27985
Related to #21121. Replaces the remaining part of #21124.
Visual Proof
Hidden-Electron capture (
ORCA_E2E_HEADLESS=1,ORCA_BACKGROUND_LAUNCH=1, CDP screenshot, temp profile, automated).src/index.tsis open; a second clean record for the same file and owner is injected through the store and shown in a pinned tab (the duplicate state from #21121 cannot be produced on purpose through the UI, so it is seeded). Then the first record is closed withcloseFile.Before,
main(41fc9542b3): closing the first record removes both tabs. The pinned one is gone and the editor area is empty.After, this branch (
e27353a12c): the pinned tab stays, still pinned, still showing the file.The
setActiveFileguard has no visual surface; it is covered byeditor-set-active-file-guard.test.ts.Testing
Unit and integration tests, macOS, on
e27353a12c:editor-close-pinned-sibling.test.ts:editor-set-active-file-guard.test.ts:e27353a12c(store/slices/editor/, theeditor-*suites andactive-selection-owner-scoping): 33 test files, 334 tests pass.e27353a12c:pnpm tcandpnpm run check:code-quality:changed(0 new findings across 4 files) pass; the layout-writer, focus-read and max-lines ratchets,check:reliability-gatesandcheck:compat-boundary-importspassed on the previous head5f06eff368, which differs only in a test file.Not run: Linux, Windows, SSH. Electron was run only for the hidden-renderer capture above (macOS, temp profile, automated), not a manual session.
AI Disclosure
Written with Claude Code (Claude Opus 5.5) and Codex (gpt-6-astra).
Review
Agent skill upstream boundary
Notes
isSameOwnedDocument.Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred). Typecheck, changed-code quality and the related suites pass locally. Full lint, the full test suite and the build are left to CI.