mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
macos: split traversal uses direction to determine proper focus target
Fixes #415
This commit is contained in:
@ -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