Skip to content

fix(tabs): single-click reuses the active tab window-locally (#1348)#1394

Merged
datlechin merged 1 commit into
mainfrom
fix-1348-tab-replace
May 22, 2026
Merged

fix(tabs): single-click reuses the active tab window-locally (#1348)#1394
datlechin merged 1 commit into
mainfrom
fix-1348-tab-replace

Conversation

@datlechin
Copy link
Copy Markdown
Member

Fixes #1348.

Problem

The first table click replaced the current tab, but once a second tab existed, every later click opened a new tab instead of replacing the active one.

Root cause

The replace-vs-new-tab decision was made outside the focused window. openPreviewTab scanned every window of the connection for a preview flag and replaced whichever window held it, stealing focus to a different window. That window-level preview flag was a second source of truth that drifted out of sync with QueryTab.isPreview. With preview tabs off there was no reuse path at all, so every click spawned a tab.

Fix

Single-click is now window-local, with QueryTab.isPreview as the only source of truth:

  • Reuse the focused window's active tab when it is reusable (a preview tab or a blank query tab) and has no unsaved work.
  • Otherwise open a new tab and leave the current one alone.
  • enablePreviewTabs only decides whether the resulting tab is a preview.

This matches the macOS convention (single-click opens in place, double-click opens) and the Xcode/VS Code one-temporary-tab model. Pinned and working tabs are protected; double-click opens a table in its own permanent tab.

Removed the cross-window preview lookup (WindowLifecycleMonitor.previewWindow/setPreview/Entry.isPreview) and deleted openPreviewTab.

Tests

  • Rewrote SidebarNavigationResultTests for the new .skip / .reuseActiveTab / .openNewTab contract.
  • Added coordinator tests in OpenTableTabTests: window-local reuse (preview on, and a blank query tab), pinned-tab protection, promotion, and double-click opening a permanent tab.

swiftlint --strict clean.

@datlechin datlechin force-pushed the fix-1348-tab-replace branch from 97e41c3 to cdf6c8c Compare May 22, 2026 17:05
@datlechin datlechin merged commit 967a1b9 into main May 22, 2026
2 checks passed
@datlechin datlechin deleted the fix-1348-tab-replace branch May 22, 2026 17:06
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.

Table selection inconsistently replaces tab vs opens a new tab

1 participant