summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 13:42:38 -0300
committerGabriel Schneider <[email protected]>2026-10-24 15:41:50 -0300
commitb32447e0b265f25ad7807760956bedf8cf42664d (patch)
tree7d2fa5bbf88af4a1ce07a911709e33448aa6e161 /src/pardes.zig
parentf3b5bd10ceb4c4db7263739770d5e4bdb879ba75 (diff)
downloadpardes-b32447e0b265f25ad7807760956bedf8cf42664d.tar.gz
pardes-b32447e0b265f25ad7807760956bedf8cf42664d.zip
Window mode: d deletes the outlined pane (Del's k/j question, the outline following its rows), c collapses it
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 6f30d6ca..f4158808 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -6301,6 +6301,8 @@ pub const Pardes = struct {
asked.prompt = .none;
if (choice == 'k') exec.runBuiltin(p, .Del, id, "", "k");
if (choice == 'j') exec.runBuiltin(p, .Del, id, "", "j");
+ // Asked from window mode (`d`): the outline goes with the rows.
+ if (p.window_pick == id and p.panes[id] == null) p.window_pick = if (p.header_focus) null else p.active;
},
else => return false,
}
@@ -8620,6 +8622,61 @@ test "window mode moves an outline and focuses it on Enter, Esc or a label" {
try std.testing.expectEqualStrings("a", box.text[0..box.len]);
}
+test "window mode d deletes the outlined pane and asks k or j, c collapses it, and the mode stays" {
+ if (platform == .web) return;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 });
+ defer p.deinit();
+ p.settings.placement = .pardes; // the neighbours below are what is under test
+ const top = p.active;
+ p.newScratchBelow(top);
+ const mid = p.active;
+ p.newScratchBelow(mid);
+ const low = p.active;
+ p.sync();
+ const h = [_]u16{ p.rects[top].h, p.rects[mid].h, p.rects[low].h };
+ // Neither key is a pane's label.
+ try std.testing.expect(std.mem.indexOfAny(u8, layout.window_labels, "hjkldc") == null);
+
+ // Ctrl-w from the bottom pane, the outline up to the middle one.
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ p.update(.{ .key = .{ .cp = 'k', .text = "k" } });
+ try std.testing.expectEqual(@as(?usize, mid), p.window_pick);
+ // c folds the outlined pane to its tag and back, the mode staying.
+ p.update(.{ .key = .{ .cp = 'c', .text = "c" } });
+ try std.testing.expect(p.panes[mid].?.collapsed);
+ try std.testing.expectEqual(@as(?usize, mid), p.window_pick);
+ p.update(.{ .key = .{ .cp = 'c', .text = "c" } });
+ try std.testing.expect(!p.panes[mid].?.collapsed);
+ p.sync();
+ try std.testing.expectEqual(h[1], p.rects[mid].h);
+
+ // d with panes above and below asks, as SPC d does; Esc takes it back
+ // and the outline stays where it was.
+ p.update(.{ .key = .{ .cp = 'd', .text = "d" } });
+ try std.testing.expectEqual(Pane.Prompt.del_side, p.panes[mid].?.prompt);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(p.panes[mid] != null and p.panes[mid].?.prompt == .none);
+ try std.testing.expectEqual(@as(?usize, mid), p.window_pick);
+ // j: the pane below takes the rows, and the outline goes with them.
+ p.update(.{ .key = .{ .cp = 'd', .text = "d" } });
+ p.update(.{ .key = .{ .cp = 'j', .text = "j" } });
+ p.sync();
+ try std.testing.expect(p.panes[mid] == null);
+ try std.testing.expectEqual(h[0], p.rects[top].h);
+ try std.testing.expectEqual(h[1] + h[2], p.rects[low].h);
+ try std.testing.expectEqual(@as(?usize, low), p.window_pick);
+ // With one neighbour there is nothing to ask: d closes it at once,
+ // the outline on the pane that grew.
+ p.update(.{ .key = .{ .cp = 'd', .text = "d" } });
+ p.sync();
+ try std.testing.expect(p.panes[low] == null);
+ try std.testing.expectEqual(@as(?usize, top), p.window_pick);
+ // Enter leaves the mode on it.
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expect(p.window_pick == null);
+ try std.testing.expectEqual(top, p.active);
+}
+
test "raw tty Ctrl-B switches to editor mode without sending child input" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml" });