-
-
Notifications
You must be signed in to change notification settings - Fork 288
fix(coordinator): activate the existing tab instead of opening a duplicate (#1613) #1623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ extension MainContentCoordinator { | |
| func openTableTab( | ||
| _ table: TableInfo, | ||
| showStructure: Bool = false, | ||
| redirectToSibling: Bool = false, | ||
| forceNonPreview: Bool = false, | ||
| activateGridFocus: Bool = false | ||
| ) { | ||
|
|
@@ -27,7 +26,6 @@ extension MainContentCoordinator { | |
| schema: table.schema, | ||
| showStructure: showStructure, | ||
| isView: table.type == .view, | ||
| redirectToSibling: redirectToSibling, | ||
| forceNonPreview: forceNonPreview, | ||
| activateGridFocus: activateGridFocus | ||
| ) | ||
|
|
@@ -38,7 +36,6 @@ extension MainContentCoordinator { | |
| schema: String? = nil, | ||
| showStructure: Bool = false, | ||
| isView: Bool = false, | ||
| redirectToSibling: Bool = false, | ||
| forceNonPreview: Bool = false, | ||
| activateGridFocus: Bool = false | ||
| ) { | ||
|
|
@@ -59,18 +56,14 @@ extension MainContentCoordinator { | |
| let resolvedSchema = schema | ||
| let createAsPreview = !forceNonPreview && AppSettingsManager.shared.tabs.enablePreviewTabs | ||
|
|
||
| // Fast path: if this table is already the active tab in the same database, skip all work | ||
| if let current = tabManager.selectedTab, | ||
| current.tabType == .table, | ||
| current.tableContext.tableName == tableName, | ||
| current.tableContext.databaseName == currentDatabase, | ||
| current.tableContext.schemaName == resolvedSchema { | ||
| if showStructure, let (_, tabIndex) = tabManager.selectedTabAndIndex { | ||
| tabManager.mutate(at: tabIndex) { $0.display.resultsViewMode = .structure } | ||
| } | ||
| if activateGridFocus { | ||
| focusActiveGrid() | ||
| } | ||
| if activateIfAlreadyOpen( | ||
| tableName: tableName, | ||
| databaseName: currentDatabase, | ||
| schemaName: resolvedSchema, | ||
| showStructure: showStructure, | ||
| activateGridFocus: activateGridFocus, | ||
| includeSiblings: navigationModel != .inPlace | ||
| ) { | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -98,28 +91,6 @@ extension MainContentCoordinator { | |
| return | ||
| } | ||
|
|
||
| // Opt-in cross-window navigation: if requested (e.g. quick switcher), | ||
| // and another window already shows this table, focus that window. | ||
| // Default-off so sidebar clicks and other window-local actions stay | ||
| // window-local instead of stealing focus to a sibling. | ||
| if redirectToSibling { | ||
| for sibling in MainContentCoordinator.allActiveCoordinators() | ||
| where sibling !== self && sibling.connectionId == connectionId { | ||
| let hasMatch = sibling.tabManager.tabs.contains { tab in | ||
| tab.tabType == .table | ||
| && tab.tableContext.tableName == tableName | ||
| && tab.tableContext.databaseName == currentDatabase | ||
| && tab.tableContext.schemaName == resolvedSchema | ||
| } | ||
| guard hasMatch, | ||
| let windowId = sibling.windowId, | ||
| let window = WindowLifecycleMonitor.shared.window(for: windowId) else { continue } | ||
| pendingGridFocusOnOpen = false | ||
| window.makeKeyAndOrderFront(nil) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // If no tabs exist (empty state), add a table tab directly. | ||
| if tabManager.tabs.isEmpty { | ||
| addFirstTableTab( | ||
|
|
@@ -191,6 +162,50 @@ extension MainContentCoordinator { | |
| WindowManager.shared.openTab(payload: payload) | ||
| } | ||
|
|
||
| func activateIfAlreadyOpen( | ||
| tableName: String, | ||
| databaseName: String, | ||
| schemaName: String?, | ||
| showStructure: Bool, | ||
| activateGridFocus: Bool, | ||
| includeSiblings: Bool | ||
| ) -> Bool { | ||
| func matches(_ tab: QueryTab) -> Bool { | ||
| tab.tabType == .table | ||
| && tab.tableContext.tableName == tableName | ||
| && tab.tableContext.databaseName == databaseName | ||
| && tab.tableContext.schemaName == schemaName | ||
| } | ||
|
|
||
| if let match = tabManager.tabs.first(where: matches) { | ||
| if tabManager.selectedTabId != match.id { | ||
| tabManager.selectedTabId = match.id | ||
| } | ||
| applyStructureMode(showStructure, toTab: match.id, in: tabManager) | ||
| if activateGridFocus { | ||
| requestGridFocus() | ||
| } | ||
| return true | ||
|
Comment on lines
+180
to
+188
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| guard includeSiblings else { return false } | ||
|
|
||
| for sibling in MainContentCoordinator.allActiveCoordinators() | ||
| where sibling !== self && sibling.connectionId == connectionId { | ||
| guard let match = sibling.tabManager.tabs.first(where: matches) else { continue } | ||
| sibling.pendingGridFocusOnOpen = activateGridFocus | ||
| applyStructureMode(showStructure, toTab: match.id, in: sibling.tabManager) | ||
| sibling.selectTabAndFocusWindow(match.id) | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| private func applyStructureMode(_ showStructure: Bool, toTab tabId: UUID, in tabManager: QueryTabManager) { | ||
| guard showStructure, let index = tabManager.tabs.firstIndex(where: { $0.id == tabId }) else { return } | ||
| tabManager.mutate(at: index) { $0.display.resultsViewMode = .structure } | ||
| } | ||
|
|
||
| private func addFirstTableTab( | ||
| tableName: String, | ||
| currentDatabase: String, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
activateGridFocusis true and the match is a non-selected tab in the same window, this callsrequestGridFocus()immediately after changingselectedTabId. At that point SwiftUI has not rebuilt the content for the new tab yet, sodataTabDelegatecan still point at the outgoing table; if itsfocusGrid()succeeds,pendingGridFocusOnOpenis cleared and the newly selected table never consumes it inKeyHandlingTableView.viewDidMoveToWindow(). Sidebar/quick-switcher opens of an already-open tab can therefore leave keyboard focus on the old grid instead of the activated table.Useful? React with 👍 / 👎.