fix(tabs): keep safe-mode confirmation on the active tab (#1781)#1785
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
NSWindowsharing oneconnectionId(native NSWindow tabbing). The safe-mode confirmation anchored its sheet toWindowLifecycleMonitor.findWindow(for:), which returns the first visible window from an unordered dictionary. Background tabs in a native tab group all reportisVisible, 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
WindowLifecycleMonitorgainsactiveWindow(for:preferring:), which returns the supplied candidate (the key window) when it belongs to the connection, otherwise falls back tofindWindow.findWindow's "any visible window" behavior is left intact for its other caller (TabRouter).AlertOperationConfirming.confirmanchors the sheet toactiveWindow(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.