Skip to content

fix(tabs): keep safe-mode confirmation on the active tab (#1781)#1785

Merged
datlechin merged 1 commit into
mainfrom
fix/safe-mode-tab-1781
Jun 29, 2026
Merged

fix(tabs): keep safe-mode confirmation on the active tab (#1781)#1785
datlechin merged 1 commit into
mainfrom
fix/safe-mode-tab-1781

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

Fixes #1781. With safe mode on, running a query on a tab that is not the first tab and confirming the dialog switched the active tab to the first tab. It now stays on the tab the query was run from.

Root cause

Each editor tab is a separate NSWindow sharing one connectionId (native NSWindow tabbing). The safe-mode confirmation anchored its sheet to WindowLifecycleMonitor.findWindow(for:), which returns the first visible window from an unordered dictionary. Background tabs in a native tab group all report isVisible, so it picked an arbitrary tab's window. beginSheetModal(for:) then brought that window's tab forward, and it stayed selected after confirmation. The query itself ran on the correct tab; only the visible tab was wrong.

Fix

  • WindowLifecycleMonitor gains activeWindow(for:preferring:), which returns the supplied candidate (the key window) when it belongs to the connection, otherwise falls back to findWindow. findWindow's "any visible window" behavior is left intact for its other caller (TabRouter).
  • AlertOperationConfirming.confirm anchors the sheet to activeWindow(for: connectionId, preferring: NSApp.keyWindow), captured before presenting, so the sheet appears on the originating tab and selection does not change.

Covers both plain and parameterized execution, which share the same confirm step. Matches the HIG modality rule that a confirmation returns the user to where they were.

Tests

WindowLifecycleMonitorTests: prefers a matching candidate, ignores a candidate from another connection, falls back when the candidate is nil.

Manual check

Open two tabs on one connection, enable safe mode, run a query on the second tab, confirm. The second tab stays active.

@datlechin datlechin merged commit 0191c2a into main Jun 29, 2026
2 of 3 checks passed
@datlechin datlechin deleted the fix/safe-mode-tab-1781 branch June 29, 2026 22:40
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.

Bug: Safe Mode - Move to first tab post confirmation

1 participant