macos: handle split zooming

This commit is contained in:
Mitchell Hashimoto
2025-06-04 11:23:55 -07:00
parent b7c01b5b4a
commit ea1ff438f8
2 changed files with 28 additions and 2 deletions

View File

@@ -5,8 +5,11 @@ struct TerminalSplitTreeView: View {
let onResize: (SplitTree<Ghostty.SurfaceView>.Node, Double) -> Void
var body: some View {
if let node = tree.root {
TerminalSplitSubtreeView(node: node, isRoot: true, onResize: onResize)
if let node = tree.zoomed ?? tree.root {
TerminalSplitSubtreeView(
node: node,
isRoot: node == tree.root,
onResize: onResize)
}
}
}

View File

@@ -150,6 +150,11 @@ class BaseTerminalController: NSWindowController,
selector: #selector(ghosttyDidFocusSplit(_:)),
name: Ghostty.Notification.ghosttyFocusSplit,
object: nil)
center.addObserver(
self,
selector: #selector(ghosttyDidToggleSplitZoom(_:)),
name: Ghostty.Notification.didToggleSplitZoom,
object: nil)
// Listen for local events that we need to know of outside of
// single surface handlers.
@@ -422,6 +427,24 @@ class BaseTerminalController: NSWindowController,
// Move focus to the next surface
Ghostty.moveFocus(to: nextSurface, from: target)
}
@objc private func ghosttyDidToggleSplitZoom(_ notification: Notification) {
// The target must be within our tree
guard let target = notification.object as? Ghostty.SurfaceView else { return }
guard let targetNode = surfaceTree2.root?.node(view: target) else { return }
// Toggle the zoomed state
if surfaceTree2.zoomed == targetNode {
// Already zoomed, unzoom it
surfaceTree2 = SplitTree(root: surfaceTree2.root, zoomed: nil)
} else {
// Not zoomed or different node zoomed, zoom this node
surfaceTree2 = SplitTree(root: surfaceTree2.root, zoomed: targetNode)
}
// Ensure focus stays on the target surface
Ghostty.moveFocus(to: target)
}
// MARK: Local Events