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:
Steven Lu
2026-01-19 17:34:34 +07:00
parent 250877eff6
commit 6db4e437ca
3 changed files with 83 additions and 12 deletions

View File

@@ -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;