From ab8dfab9de0d2900808fb9dd7a133d840fd30f30 Mon Sep 17 00:00:00 2001 From: Ryota Date: Fri, 12 Jan 2024 00:52:26 +0000 Subject: [PATCH] Add helper func for first and last leaf --- macos/Sources/Ghostty/Ghostty.SplitNode.swift | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/macos/Sources/Ghostty/Ghostty.SplitNode.swift b/macos/Sources/Ghostty/Ghostty.SplitNode.swift index daf059864..8c0fe406d 100644 --- a/macos/Sources/Ghostty/Ghostty.SplitNode.swift +++ b/macos/Sources/Ghostty/Ghostty.SplitNode.swift @@ -271,6 +271,30 @@ extension Ghostty { return parent.rootContainer() } + /// Returns the first leaf from the given container. This is most + /// useful for root container, so that we can find the top-left-most + /// leaf. + func firstLeaf() -> Leaf { + switch (self.topLeft) { + case .leaf(let leaf): + return leaf + case .split(let s): + return s.firstLeaf() + } + } + + /// Returns the last leaf from the given container. This is most + /// useful for root container, so that we can find the bottom-right- + /// most leaf. + func lastLeaf() -> Leaf { + switch (self.bottomRight) { + case .leaf(let leaf): + return leaf + case .split(let s): + return s.lastLeaf() + } + } + // MARK: - Hashable func hash(into hasher: inout Hasher) {