summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.zig5
-rw-r--r--src/layout.zig23
-rw-r--r--src/pardes.zig57
3 files changed, 80 insertions, 5 deletions
diff --git a/src/config.zig b/src/config.zig
index fff99ad2..2cb66c0a 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -303,6 +303,11 @@ pub const window_keys = [_]struct { letter: Chord, arrow: Chord, cmd: Builtin }{
.{ .letter = .{ .cp = 'l' }, .arrow = .{ .cp = Key.right }, .cmd = .Right },
};
+// In window mode `d` is Del on the outlined pane, its k/j question and all,
+// the outline going with the rows; `c` is Collapse. Neither is a label.
+pub const window_delete: []const Chord = &.{.{ .cp = 'd' }};
+pub const window_collapse: []const Chord = &.{.{ .cp = 'c' }};
+
pub const new_shell_below: []const Chord = &.{.{ .cp = 'n', .alt = true }};
pub const pane_to_new_column: []const Chord = &.{.{ .cp = 'c', .alt = true }};
diff --git a/src/layout.zig b/src/layout.zig
index 8739122c..e674ccbf 100644
--- a/src/layout.zig
+++ b/src/layout.zig
@@ -70,9 +70,10 @@ pub fn nearest(p: *const Pardes, from: usize, dir: Dir) ?usize {
}
/// Window mode's labels, one a pane in reading order (columns left to
-/// right, each top to bottom); h, j, k and l move instead. ponytail: a
-/// pane past the 22nd has no label and is reached by moving.
-pub const window_labels = "asdfgqwertyuiopzxcvbnm";
+/// right, each top to bottom); h, j, k and l move instead, d deletes and c
+/// collapses. ponytail: a pane past the 20th has no label and is reached
+/// by moving.
+pub const window_labels = "asfgqwertyuiopzxvbnm";
/// The letter window mode shows on pane `id`.
pub fn windowLabel(p: *const Pardes, id: usize) ?u8 {
@@ -88,8 +89,11 @@ pub fn windowLabel(p: *const Pardes, id: usize) ?u8 {
/// Window mode (SPC w, Ctrl-w): h/j/k/l (or the arrows) move an outline
/// from pane to pane and nothing else gets the keys; Enter or Esc focuses
/// the outlined pane, `:` its tag, and a pane's label letter that one. Up past a
-/// column's top pane goes on to its tag, as the Up word does. Any other
-/// key changes nothing.
+/// column's top pane goes on to its tag, as the Up word does. `d` is Del
+/// on the outlined pane and `c` Collapse, and the mode stays: a Del that
+/// closes it moves the outline to the pane its rows went to (after the k/j
+/// question, when Del asks one; Pardes.answerQuestion). Any other key
+/// changes nothing.
pub fn windowKey(p: *Pardes, key: pardes.Key) void {
const at = p.window_pick orelse return;
if (p.panes[at] == null) {
@@ -113,6 +117,15 @@ pub fn windowKey(p: *Pardes, key: pardes.Key) void {
}
return;
};
+ if (pardes.hit(key, config.window_collapse)) return pardes.exec.runBuiltin(p, .Collapse, at, "", null);
+ if (pardes.hit(key, config.window_delete)) {
+ // Del's focus follows the rows from the pane it closes, so the
+ // outlined pane is the active one while it runs.
+ p.active = at;
+ pardes.exec.runBuiltin(p, .Del, at, "", null);
+ if (p.panes[at] == null) p.window_pick = if (p.header_focus) null else p.active;
+ return;
+ }
const chosen = if (key.cp == pardes.Key.enter or key.cp == pardes.Key.escape or key.cp == ':') at else for (0..p.panes.len) |id| {
if (p.panes[id] != null and key.cp < 128 and windowLabel(p, id) == @as(u8, @intCast(key.cp))) break id;
} else return;
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" });