Skip to content

fix(tabs): restore Cmd/Ctrl+Shift+T tab positions - #12236

Merged
nwparker merged 3 commits into
mainfrom
nwparker/cmd-shift-t-restore-doesn-t-restore-tab-position
Aug 3, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/cmd-shift-t-restore-doesn-t-restore-tab-position

Conversation

@nwparker

@nwparker nwparker commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

ELI5

Cmd/Ctrl+Shift+T used to remember what tab was closed, but not reliably which tab when two tabs showed the same file or when tabs lived in split groups. On restore, Orca looked up the first matching file path, so the wrong tab could jump.

This change:

  • captures the tab bar and split-group position before editor, terminal, browser, and close-all removal;
  • restores the exact editor/diff/owner ID instead of searching by path alone;
  • selects the unified tab in the captured split group;
  • ignores a stale legacy flat index after split-group drag reordering.

Proof

Before — the reopened tab appended/moved to the wrong position:

https://github.com/user-attachments/assets/45891afa-fe59-423d-962f-b741bf21ea85

After — Cmd/Ctrl+Shift+T restores the original position:

https://github.com/user-attachments/assets/0f68fb35-b225-4359-892f-e150f9f74c6b

Validation

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/store/slices/editor.test.ts src/renderer/src/store/slices/recently-closed-tabs.test.ts — 210 passed
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/store/slices/browser.test.ts — 33 passed
  • pnpm run typecheck:web — passed
  • Oxlint — passed, including pre-commit hooks
  • Oxfmt — passed
  • git diff --check — passed

Regression coverage includes same-path local/runtime owners, same-path edit/diff tabs, split-order drift, and close-all editor restores.

Release-scan note

The requested $prod-release-scan executable is not installed in this workspace. The prior panel run (run_c9644635582) was cancelled after the user stopped the orchestration workers, so I am not claiming that panel scan passed. The generated reports were kept out of this PR; the focused local checks above and pre-commit gates are green.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0fede72a-f575-4680-b047-332e5ddb1b12

📥 Commits

Reviewing files that changed from the base of the PR and between d48cac7 and 5f33e66.

📒 Files selected for processing (6)
  • src/renderer/src/store/slices/browser.ts
  • src/renderer/src/store/slices/editor.test.ts
  • src/renderer/src/store/slices/editor.ts
  • src/renderer/src/store/slices/recently-closed-tabs.test.ts
  • src/renderer/src/store/slices/recently-closed-tabs.ts
  • src/renderer/src/store/slices/terminals.ts

📝 Walkthrough

Walkthrough

Recently closed browser, editor, and terminal snapshots now store tab-bar and group positions. Reopen flows restore these positions for single-page, multi-page, editor, and terminal tabs. Editor reopening also preserves original tab IDs and distinguishes same-path edit, diff, and owner entities. Tests cover middle-tab ordering, group reordering, shared entities, and close-all snapshots.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and validation, but omits the required AI Review Report, Security Audit, and Notes sections. Add the missing template sections and document the AI review, cross-platform checks, security audit, and platform-specific risks or follow-up work.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the fix for restoring tab positions with the Cmd/Ctrl+Shift+T shortcut.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit 18dbcf0 into main Aug 3, 2026
43 checks passed
OrcaWin added a commit that referenced this pull request Aug 4, 2026
…arge tab sets (#12404)

* fix(editor): stop Cmd/Ctrl+Shift+T reopening a phantom editor tab

`openFile` honored a recently-closed snapshot's `reopenId` whenever no
open file currently held that id, without checking whether the same
(path, mode, owner) was already open under a different id. Editor ids
are not symmetrical across worktrees: the first worktree to open an
absolute path gets the bare path as its id, and any other owner of the
same path gets a namespaced `editor:<wt>:<runtime>:<path>` id. So a
snapshot captured under one shape could be restored while the live tab
carried the other.

When that happened `openFile` took the `existing` branch and mapped over
`openFiles` looking for the stale id, matching nothing — no OpenFile was
created or updated — yet it still set `activeFileId`, the per-worktree
active id, the tab bar order and a unified tab entity to that stale id.
The user got a tab rendering nothing and a dangling active editor.

Resolve the id from the already-open file whenever one exists, so capture
and restore agree on canonicalization. This is a no-op for the non-reopen
path, where `resolveEditorFileIdForOwner` already returns `existing.id`
via the identical predicate.

* fix(editor): make Close All linear instead of cubic in tab count

closeAllFiles resolved a reopen position for every closing tab by calling
getRecentlyClosedTabPosition, which itself rescanned the worktree's tab-bar
order and group membership with a nested find per entry. That made the whole
bulk close O(N^3) in open editor tabs, and because it runs inside a synchronous
zustand set() the renderer is blocked for the entire duration: measured against
the real store, 500 tabs took 1.2s and 1000 tabs took 13.0s of frozen UI.
Sessions that accumulate tabs — long SSH/relay work, a mirrored host republishing
open files, a folder workspace opened wide — hit this on a single menu click.

Hoist the per-tab rescans into one precomputed index. The new
createRecentlyClosedTabPositionIndex builds tab-bar, unified-tab, and group
lookups in a single linear pass over the worktree's state, then answers each
position query in O(1); getRecentlyClosedTabPosition now delegates to it so
single-tab callers keep identical behavior. Positions, reopen order, and the
tab-bar/group indices recorded by #12236 are unchanged — first-occurrence wins
everywhere, matching the indexOf/find scans this replaces.

Position derivation moves to its own module so recently-closed-tabs.ts stays
under the max-lines limit without a suppression; existing importers are
unaffected via re-export.

Same measurement after the change: 500 tabs 44ms, 1000 tabs 142ms, and the
instrumented scan count drops from 503,000,500 to 4,000 at N=1000.

---------

Co-authored-by: OrcaWin <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…arge tab sets (stablyai#12404)

* fix(editor): stop Cmd/Ctrl+Shift+T reopening a phantom editor tab

`openFile` honored a recently-closed snapshot's `reopenId` whenever no
open file currently held that id, without checking whether the same
(path, mode, owner) was already open under a different id. Editor ids
are not symmetrical across worktrees: the first worktree to open an
absolute path gets the bare path as its id, and any other owner of the
same path gets a namespaced `editor:<wt>:<runtime>:<path>` id. So a
snapshot captured under one shape could be restored while the live tab
carried the other.

When that happened `openFile` took the `existing` branch and mapped over
`openFiles` looking for the stale id, matching nothing — no OpenFile was
created or updated — yet it still set `activeFileId`, the per-worktree
active id, the tab bar order and a unified tab entity to that stale id.
The user got a tab rendering nothing and a dangling active editor.

Resolve the id from the already-open file whenever one exists, so capture
and restore agree on canonicalization. This is a no-op for the non-reopen
path, where `resolveEditorFileIdForOwner` already returns `existing.id`
via the identical predicate.

* fix(editor): make Close All linear instead of cubic in tab count

closeAllFiles resolved a reopen position for every closing tab by calling
getRecentlyClosedTabPosition, which itself rescanned the worktree's tab-bar
order and group membership with a nested find per entry. That made the whole
bulk close O(N^3) in open editor tabs, and because it runs inside a synchronous
zustand set() the renderer is blocked for the entire duration: measured against
the real store, 500 tabs took 1.2s and 1000 tabs took 13.0s of frozen UI.
Sessions that accumulate tabs — long SSH/relay work, a mirrored host republishing
open files, a folder workspace opened wide — hit this on a single menu click.

Hoist the per-tab rescans into one precomputed index. The new
createRecentlyClosedTabPositionIndex builds tab-bar, unified-tab, and group
lookups in a single linear pass over the worktree's state, then answers each
position query in O(1); getRecentlyClosedTabPosition now delegates to it so
single-tab callers keep identical behavior. Positions, reopen order, and the
tab-bar/group indices recorded by stablyai#12236 are unchanged — first-occurrence wins
everywhere, matching the indexOf/find scans this replaces.

Position derivation moves to its own module so recently-closed-tabs.ts stays
under the max-lines limit without a suppression; existing importers are
unaffected via re-export.

Same measurement after the change: 500 tabs 44ms, 1000 tabs 142ms, and the
instrumented scan count drops from 503,000,500 to 4,000 at N=1000.

---------

Co-authored-by: OrcaWin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant