Skip to content

fix: Restore tab position within workspace on cross-workspace undo close tab#12341

Open
7ito wants to merge 1 commit intozen-browser:devfrom
7ito:fix/restore-tab-workspace-position
Open

fix: Restore tab position within workspace on cross-workspace undo close tab#12341
7ito wants to merge 1 commit intozen-browser:devfrom
7ito:fix/restore-tab-workspace-position

Conversation

@7ito
Copy link

@7ito 7ito commented Feb 12, 2026

When a tab is closed in one workspace and restored (Ctrl+Shift+T) from a different workspace, the tab was always appended to the bottom of the workspace's tab list instead of its original position/index.

This implements a fix that saves the workspace tab index at close time and uses it to insert the tab at the correct position during restore.

Changes:

  • SessionStore.sys.mjs — compute and save zenWorkspaceTabIndex in maybeSaveClosedTab, pass it through in undoCloseTab
  • tabbrowser.js — accept zenWorkspaceTabIndex in addTab, set it as a transient attribute on the tab element
  • ZenWorkspaces.mjs — read the attribute in onTabBrowserInserted, use it in moveTabToWorkspace to insert at the correct position (excluding the empty tab from index calculations)

@7ito 7ito requested a review from mr-cheffy as a code owner February 12, 2026 08:53
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Bug labels Feb 12, 2026
@mr-cheffy
Copy link
Member

I would rather figure out why the tab isn't positioned at the correct position in the first time. Maybe we should use the tab's "current" position before switching its space and tanslate it over?

}

moveTabsToWorkspace(tabs, workspaceID) {
moveTabsToWorkspace(tabs, workspaceID, tabIndex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant was that, we dont need this as a parameter. We can just use the same location the tab would be in before gBrowser.zenHandleTabMove. You could use, for example, tab._tPos

… as _zenRestoreTPos in tabbrowser. zenWorkspaces uses _zenRestoreTPos ?? _tPos with >= comparison, clears the transient field after the move, and inserts in the correct index (before the correct workspace item).
@7ito 7ito force-pushed the fix/restore-tab-workspace-position branch from cbfa4e7 to ade5415 Compare February 13, 2026 04:00
@7ito
Copy link
Author

7ito commented Feb 13, 2026

To avoid adding a parameter to moveTabsToWorkspace, the restore flow now records a tab’s pre‑close position as a short‑lived _zenRestoreTPos, which is used to pick the insertion point in the workspace (normal tabs only). About the >= condition: once a tab closes, everything after it shifts up by one, so using >= lines up the pre‑close position with the right slot and avoids the off‑by‑one jump. I think this approach keeps the original order across workspaces without persisting extra state or changing method signatures now?

Thanks for the reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants