mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
Merge pull request #422 from mitchellh/split-traversal
macos: split traversal uses direction to determine proper focus target
This commit is contained in:
@ -32,10 +32,6 @@ class PrimaryWindowManager {
|
||||
let mainManagedWindow = managedWindows
|
||||
.first { $0.window.isMainWindow }
|
||||
|
||||
// In case we run into the inconsistency, let it crash in debug mode so we
|
||||
// can fix our window management setup to prevent this from happening.
|
||||
assert(mainManagedWindow != nil || !managedWindows.isEmpty)
|
||||
|
||||
return (mainManagedWindow ?? managedWindows.first)
|
||||
.map { $0.window }
|
||||
}
|
||||
|
@ -54,17 +54,30 @@ extension Ghostty {
|
||||
/// Returns the view that would prefer receiving focus in this tree. This is always the
|
||||
/// top-left-most view. This is used when creating a split or closing a split to find the
|
||||
/// next view to send focus to.
|
||||
func preferredFocus() -> SurfaceView {
|
||||
func preferredFocus(_ direction: SplitFocusDirection = .top) -> SurfaceView {
|
||||
let container: Container
|
||||
switch (self) {
|
||||
case .noSplit(let leaf):
|
||||
// noSplit is easy because there is only one thing to focus
|
||||
return leaf.surface
|
||||
|
||||
case .horizontal(let container):
|
||||
return container.topLeft.preferredFocus()
|
||||
case .horizontal(let c):
|
||||
container = c
|
||||
|
||||
case .vertical(let container):
|
||||
return container.topLeft.preferredFocus()
|
||||
case .vertical(let c):
|
||||
container = c
|
||||
}
|
||||
|
||||
let node: SplitNode
|
||||
switch (direction) {
|
||||
case .previous, .bottom, .left:
|
||||
node = container.bottomRight
|
||||
|
||||
case .next, .top, .right:
|
||||
node = container.topLeft
|
||||
}
|
||||
|
||||
return node.preferredFocus(direction)
|
||||
}
|
||||
|
||||
/// Close the surface associated with this node. This will likely deinitialize the
|
||||
@ -405,7 +418,10 @@ extension Ghostty {
|
||||
guard let directionAny = notification.userInfo?[Notification.SplitDirectionKey] else { return }
|
||||
guard let direction = directionAny as? SplitFocusDirection else { return }
|
||||
guard let next = neighbors.get(direction: direction) else { return }
|
||||
Ghostty.moveFocus(to: next.preferredFocus(), from: node.preferredFocus())
|
||||
Ghostty.moveFocus(
|
||||
to: next.preferredFocus(direction),
|
||||
from: node.preferredFocus()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user