Repository navigation
Fix drag-to-split cursor focus reconciliation #9754
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import AppKit | ||
| import Bonsplit | ||
|
|
||
| extension Workspace { | ||
| enum MovingTabSplitFocusIntent { | ||
| case activateMovedTab | ||
| case preserveCurrent | ||
| } | ||
|
|
||
| /// Moves an existing tab into a new split while making focus intent explicit. | ||
| /// | ||
| /// Bonsplit updates its focused pane synchronously but emits only `didSplitPane` | ||
| /// for this operation. The scoped intent lets that delegate callback either | ||
| /// commit the moved tab through Workspace's focus owner or restore the previous | ||
| /// Bonsplit pane and any responder focus that panel actually owned. | ||
| @discardableResult | ||
| func splitPaneMovingTab( | ||
| _ paneId: PaneID? = nil, | ||
| orientation: SplitOrientation, | ||
| movingTab tabId: TabID, | ||
| insertFirst: Bool, | ||
| focusIntent: MovingTabSplitFocusIntent | ||
| ) -> PaneID? { | ||
| let previousIntent = activeMovingTabSplitFocusIntent | ||
| let previousFocusedPanelId = focusedPanelId | ||
| let previousOwnedFocusIntent = previousFocusedPanelId | ||
| .flatMap { panels[$0] } | ||
| .flatMap { ownedFocusIntent(for: $0) } | ||
| activeMovingTabSplitFocusIntent = focusIntent | ||
| defer { activeMovingTabSplitFocusIntent = previousIntent } | ||
|
|
||
| guard let newPaneId = bonsplitController.splitPane( | ||
| paneId, | ||
| orientation: orientation, | ||
| movingTab: tabId, | ||
| insertFirst: insertFirst | ||
| ) else { | ||
| return nil | ||
| } | ||
|
|
||
| if case .preserveCurrent = focusIntent, | ||
| let previousFocusedPanelId, | ||
| let previousPaneId = self.paneId(forPanelId: previousFocusedPanelId), | ||
| let previousTabId = surfaceIdFromPanelId(previousFocusedPanelId) { | ||
| if bonsplitController.selectedTab(inPane: previousPaneId)?.id != previousTabId { | ||
| bonsplitController.selectTab(previousTabId) | ||
| } | ||
| if bonsplitController.focusedPaneId != previousPaneId { | ||
| bonsplitController.focusPane(previousPaneId) | ||
| } | ||
| if let previousOwnedFocusIntent { | ||
| focusPanel( | ||
| previousFocusedPanelId, | ||
| focusIntent: previousOwnedFocusIntent | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| return newPaneId | ||
| } | ||
|
|
||
| var preservesFocusDuringMovingTabSplit: Bool { | ||
| if case .preserveCurrent? = activeMovingTabSplitFocusIntent { | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| /// Commits the moved tab while protecting the terminal that owns AppKit focus | ||
| /// from the responder churn caused by the following SwiftUI reparent pass. | ||
| func activateMovedTabAfterSplit(_ tabId: TabID, inPane paneId: PaneID) { | ||
| let previousHostedView = terminalHostedViewOwningFirstResponder() | ||
| let terminalFocusPanelId = panelIdFromSurfaceId(tabId).flatMap { panelId in | ||
| terminalPanel(for: panelId) == nil ? nil : panelId | ||
| } | ||
|
|
||
| suppressReparentFocusUntilLayoutFollowUp( | ||
| previousHostedView, | ||
| reason: "workspace.movingTabSplitReparent", | ||
| terminalFocusPanelId: terminalFocusPanelId | ||
| ) | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| applyTabSelection( | ||
| tabId: tabId, | ||
| inPane: paneId, | ||
| previousTerminalHostedView: previousHostedView | ||
| ) | ||
| } | ||
|
|
||
| private func ownedFocusIntent(for panel: any Panel) -> PanelFocusIntent? { | ||
| guard let window = NSApp.keyWindow, | ||
| let firstResponder = window.firstResponder else { return nil } | ||
| return panel.ownedFocusIntent(for: firstResponder, in: window) | ||
| } | ||
|
|
||
| private func terminalHostedViewOwningFirstResponder() -> GhosttySurfaceScrollView? { | ||
| guard let responder = (NSApp.keyWindow ?? NSApp.mainWindow)?.firstResponder, | ||
| let panelId = responder.cmuxTerminalFocusOwningGhosttyView()?.terminalSurface?.id else { | ||
| return nil | ||
| } | ||
| return terminalPanel(for: panelId)?.hostedView | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.