mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-17 13:02:42 +00:00
splits: make resize_split and toggle_split_zoom non-performable with single pane
When a tab contains only a single split, resize_split and toggle_split_zoom actions now return false (not performed). This allows keybindings marked with `performable: true` to pass the event through to the terminal program. The performable flag causes unperformed actions to be treated as if the binding didn't exist, so the key event is sent to the terminal instead of being consumed. - Add isSplit() helper to SplitTree to detect single-pane vs split state - Update GTK resizeSplit/toggleSplitZoom to return false when single pane - Update macOS resizeSplit/toggleSplitZoom to return Bool and check isSplit - Add unit test for isSplit method
This commit is contained in:
@@ -170,6 +170,19 @@ pub fn SplitTree(comptime V: type) type {
|
||||
return self.nodes.len == 0;
|
||||
}
|
||||
|
||||
/// Returns true if this tree has more than one split (i.e., the root
|
||||
/// is a split node). This is useful for determining if actions like
|
||||
/// resize_split or toggle_split_zoom are performable.
|
||||
pub fn isSplit(self: *const Self) bool {
|
||||
// An empty tree is not split.
|
||||
if (self.isEmpty()) return false;
|
||||
// The root node is at index 0. If it's a split, we have multiple splits.
|
||||
return switch (self.nodes[0]) {
|
||||
.split => true,
|
||||
.leaf => false,
|
||||
};
|
||||
}
|
||||
|
||||
/// An iterator over all the views in the tree.
|
||||
pub fn iterator(
|
||||
self: *const Self,
|
||||
@@ -1326,6 +1339,34 @@ const TestView = struct {
|
||||
}
|
||||
};
|
||||
|
||||
test "SplitTree: isSplit" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
||||
// Empty tree should not be split
|
||||
var empty: TestTree = .empty;
|
||||
defer empty.deinit();
|
||||
try testing.expect(!empty.isSplit());
|
||||
|
||||
// Single node tree should not be split
|
||||
var v1: TestView = .{ .label = "A" };
|
||||
var single: TestTree = try TestTree.init(alloc, &v1);
|
||||
defer single.deinit();
|
||||
try testing.expect(!single.isSplit());
|
||||
|
||||
// Split tree should be split
|
||||
var v2: TestView = .{ .label = "B" };
|
||||
var split = try single.split(
|
||||
alloc,
|
||||
.root,
|
||||
.right,
|
||||
0.5,
|
||||
&v2,
|
||||
);
|
||||
defer split.deinit();
|
||||
try testing.expect(split.isSplit());
|
||||
}
|
||||
|
||||
test "SplitTree: empty tree" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
||||
Reference in New Issue
Block a user