From 3baae1dce82a97ba96703ec18797a8890a018f7f Mon Sep 17 00:00:00 2001 From: Ryota Date: Fri, 12 Jan 2024 00:53:47 +0000 Subject: [PATCH] Wrap around split focus with next and previous --- macos/Sources/Ghostty/Ghostty.TerminalSplit.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/macos/Sources/Ghostty/Ghostty.TerminalSplit.swift b/macos/Sources/Ghostty/Ghostty.TerminalSplit.swift index 2d4b7881e..0b7eb9bb8 100644 --- a/macos/Sources/Ghostty/Ghostty.TerminalSplit.swift +++ b/macos/Sources/Ghostty/Ghostty.TerminalSplit.swift @@ -247,9 +247,19 @@ extension Ghostty { // Determine our desired direction 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 } + + // Find the next surface to move to. In most cases this should be + // finding the neighbor in provided direction, and focus it. When + // the neighbor cannot be found based on next or previous direction, + // this would instead search for first or last leaf and focus it + // instead, giving the wrap around effect. + // When other directions are provided, this can be nil, and early + // returned. + guard let nextSurface = neighbors.get(direction: direction)?.preferredFocus(direction) + ?? node?.firstOrLast(direction)?.surface else { return } + Ghostty.moveFocus( - to: next.preferredFocus(direction) + to: nextSurface ) }