Add helper func for first and last leaf

This commit is contained in:
Ryota
2024-01-12 00:52:26 +00:00
parent d9c4bd7e25
commit ab8dfab9de

View File

@ -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) {