summaryrefslogtreecommitdiff
path: root/core/Pick.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Pick.zig')
-rw-r--r--core/Pick.zig379
1 files changed, 352 insertions, 27 deletions
diff --git a/core/Pick.zig b/core/Pick.zig
index e3aec3c5..0f9134bb 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -97,10 +97,12 @@ rows: []u8 = &.{},
query: Kind.Buf(256) = .{},
at: u32 = 0,
/// The landing pane's own text while its body previews (a reading pane:
-/// put back when the picker rolls up), and its caret then.
+/// put back when the picker rolls up), and its caret and top then (put
+/// back too when it previewed its own file, with nothing set aside).
aside: ?File.State = null,
aside_row: i32 = 0,
aside_col: i32 = 0,
+aside_top: usize = 0,
/// The row the preview shows (`no_row`: none yet); asked again on the
/// frame after the cursor moves, never on the key that moved it.
shown: u32 = no_row,
@@ -112,8 +114,19 @@ marks: std.ArrayList(u32) = .empty,
/// Backspace on an empty field goes back to them.
refined: [max_refine]Refined = undefined,
nrefined: u8 = 0,
-/// The band's second step: the sources to switch to (M-h).
-spine: enum(u8) { rows, sources } = .rows,
+/// The band's second step: the sources to switch to (M-h), the acts on
+/// the picked rows (M-l, M-Enter); `edit`: the field is the act Edit's
+/// command, the query kept in `query`.
+spine: enum(u8) { rows, sources, acts, edit } = .rows,
+/// The act step's cursor, among the acts offered.
+act_at: u8 = 0,
+/// The places Walk queued (C-i steps them in the landing pane): each a
+/// path in `queue_bytes`, its line and column.
+queue: std.ArrayList(Queued) = .empty,
+queue_bytes: std.ArrayList(u8) = .empty,
+queue_at: u32 = 0,
+
+pub const Queued = struct { path: u32, len: u16, line: u32, col: u32 };
const Refined = struct { query: Kind.Buf(64) = .{}, names: Names = .{} };
@@ -122,6 +135,8 @@ const no_row = std.math.maxInt(u32);
pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void {
for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(gpa);
pk.marks.deinit(gpa);
+ pk.queue.deinit(gpa);
+ pk.queue_bytes.deinit(gpa);
pk.names.deinit(gpa);
pk.found.deinit(gpa);
pk.found_bytes.deinit(gpa);
@@ -219,7 +234,13 @@ fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void {
s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) };
pk.unrolled = true;
pk.shown = no_row;
- if (p.paneBySerial(pk.landing)) |id| s.previewing.set(id);
+ if (p.paneBySerial(pk.landing)) |id| {
+ s.previewing.set(id);
+ const pane = p.panes[id].?;
+ pk.aside_row = pane.body.cur_row;
+ pk.aside_col = pane.body.cur_col;
+ pk.aside_top = if (pane.file) |f| f.scroll else 0;
+ }
}
/// Its source begun: the names gathered, a listing started.
@@ -493,6 +514,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
try text.appendSlice(arena, pk.word.slice());
try text.append(arena, ' ');
for (pk.refined[0..pk.nrefined]) |r| try text.print(arena, "{s} | ", .{r.query.slice()});
+ if (pk.spine == .edit) try text.print(arena, "{s} | Edit ", .{pk.query.slice()});
const caret: u32 = @intCast(text.items.len + s.field.caret);
try text.appendSlice(arena, s.field.text());
const n = count(p, pk);
@@ -515,7 +537,9 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
}
const nspines: u8 = @intCast(spans.items.len);
try text.appendSlice(arena, if (ncells == 0) "" else " ");
- var first = true;
+ for (acts) |act| if (offered(pk, act)) try text.print(arena, "{s} ", .{act.word});
+ try text.appendSlice(arena, "|");
+ var first = false;
inline for (comptime std.enums.values(Source)) |src| if (src != .list) {
if (src != pk.source) {
if (!first) try text.append(arena, ' ');
@@ -541,7 +565,8 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step {
const pk = live(p) orelse return &.{};
const s = &p.view().tag_state;
const n = count(p, pk);
- const out = try arena.alloc(Band.Step, if (pk.spine == .sources) 2 else 1);
+ const out = try arena.alloc(Band.Step, if (pk.spine == .sources or pk.spine == .acts) 2 else 1);
+ if (pk.spine == .acts) out[1] = try actStep(p, pk, arena);
if (pk.spine == .sources) {
const rows = try arena.alloc(Band.Row, spine_rows.len);
for (spine_rows, rows, 0..) |src, *row, i| row.* = .{ .text = try std.fmt.allocPrint(arena, "{c} {s}", .{ src.key, src.word }), .key = 1, .index = @intCast(i), .dim = src.source == pk.source };
@@ -603,8 +628,6 @@ fn preview(p: *Pardes, pk: *Pick) void {
return;
};
pk.aside = pane.file;
- pk.aside_row = pane.body.cur_row;
- pk.aside_col = pane.body.cur_col;
pane.file = .{ .path = path, .content = bytes, .output = .{ .from = .preview }, .history = history };
} else {
const pf = &pane.file.?;
@@ -665,7 +688,15 @@ fn restore(p: *Pardes, pk: *Pick) void {
fn putBack(p: *Pardes, pk: *Pick) void {
const id = p.paneBySerial(pk.landing) orelse return;
const pane = p.panes[id].?;
- const own = pk.aside orelse return;
+ if (pk.made) return;
+ const own = pk.aside orelse {
+ // Its own file previewed: its caret and top as they were.
+ look.clearNavigationSelection(p, pane);
+ pane.body.cur_row = pk.aside_row;
+ pane.body.cur_col = pk.aside_col;
+ if (pane.file != null) File.setTop(pane, .{ .line = pk.aside_top });
+ return;
+ };
pk.aside = null;
File.deinit(p, pane, &pane.file.?);
pane.file = own;
@@ -681,7 +712,8 @@ fn putBack(p: *Pardes, pk: *Pick) void {
pub fn rollUp(p: *Pardes) void {
const pk = live(p) orelse return;
const s = &p.view().tag_state;
- pk.query.set(s.field.text());
+ if (pk.spine != .edit) pk.query.set(s.field.text());
+ pk.spine = .rows;
pk.at = s.rows.at;
pk.unrolled = false;
if (p.stream.target == pk.id) _ = p.stream.stop();
@@ -723,6 +755,22 @@ pub fn key(p: *Pardes, k: Key) void {
for (spine_rows) |src| if (plain and k.cp == src.key) return switchTo(p, pk, src.source);
return;
}
+ if (pk.spine == .acts) return actKey(p, pk, k);
+ if (pk.spine == .edit) {
+ if (plain and k.cp == Key.enter) return editRows(p, pk);
+ if (plain and k.cp == Key.backspace and s.field.len == 0 or alt and k.cp == 'h') {
+ s.field.set(pk.query.slice());
+ pk.spine = .rows;
+ return;
+ }
+ _ = s.field.key(k);
+ return;
+ }
+ if (alt and (k.cp == Key.enter or k.cp == 'l')) {
+ pk.spine = .acts;
+ pk.act_at = 0;
+ return;
+ }
if (plain and k.cp == Key.enter) return land(p, if (k.shift) .below else .walk);
if (ctrl and k.cp == 's') return land(p, .below);
if (ctrl and k.cp == 'v') return land(p, .column);
@@ -737,7 +785,7 @@ pub fn key(p: *Pardes, k: Key) void {
pk.spine = .sources;
return;
}
- if (ctrl and (k.cp == ' ' or k.cp == '@')) return refine(p, pk);
+ if (ctrl and (k.cp == ' ' or k.cp == '@')) return refine(p, pk, false);
if (ctrl and k.cp == 'q') return keep(p, pk);
if (alt and k.cp == 'p') {
pk.previews = !pk.previews;
@@ -811,13 +859,16 @@ fn markAll(p: *Pardes, pk: *Pick) void {
/// C-SPC: the rows the query keeps become the list, the query starts
/// empty; a Grep's lines and All's become names to score from here.
-fn refine(p: *Pardes, pk: *Pick) void {
+fn refine(p: *Pardes, pk: *Pick, drop: bool) void {
const s = &p.view().tag_state;
const q = std.mem.trim(u8, s.field.text(), " ");
- if (q.len == 0 or pk.nrefined == max_refine) return;
+ if (q.len == 0 and !drop or pk.nrefined == max_refine) return;
+ // Dropped: the marked rows, or the current one.
+ const current = if (count(p, pk) > 0) idOf(pk, s.rows.at) else std.math.maxInt(u32);
var next: Names = .{};
if (fuzzy(pk)) {
for (pk.names.hits.items) |h| {
+ if (drop and (if (pk.marks.items.len > 0) marked(pk, h.cand) != null else h.cand == current)) continue;
const c = pk.names.cands.items[h.cand];
next.add(p.gpa, pk.names.bytes.items[c.start..][0..c.len], c.key, c.key_len, c.base, c.ref) catch break;
}
@@ -825,6 +876,7 @@ fn refine(p: *Pardes, pk: *Pick) void {
var arena = std.heap.ArenaAllocator.init(p.gpa);
defer arena.deinit();
for (0..count(p, pk)) |i| {
+ if (drop and (if (pk.marks.items.len > 0) marked(pk, @intCast(i)) != null else i == current)) continue;
_ = arena.reset(.retain_capacity);
const row = rowAt(p, pk, arena.allocator(), i) catch break;
const at = switch (row.target) {
@@ -918,8 +970,9 @@ fn keep(p: *Pardes, pk: *Pick) void {
layout.placeNew(p, from, from, free, .doc);
}
-/// How Enter lands: a walk step, a new pane below, a new column.
-const How = enum { walk, below, column };
+/// How Enter lands: a walk step, a new pane below, a new column; `queue`:
+/// a walk step to the first, the others queued for C-i (the act Walk).
+const How = enum { walk, below, column, queue };
/// Enter: the current row, or the marked ones, looked at from the asking
/// pane (look.open, the walk's way: a reading pane steps, a held one's
@@ -927,24 +980,29 @@ const How = enum { walk, below, column };
/// The list rolls into the landing pane's trail as its word (item 4).
fn land(p: *Pardes, how: How) void {
const pk = live(p) orelse return;
- const s = &p.view().tag_state;
- const n = count(p, pk);
- if (n == 0) return;
var arena = std.heap.ArenaAllocator.init(p.gpa);
defer arena.deinit();
const a = arena.allocator();
- var picked: std.ArrayList(Target) = .empty;
- if (pk.marks.items.len == 0) {
- picked.append(a, (rowAt(p, pk, a, s.rows.at) catch return).target) catch return;
- } else for (0..n) |i| if (marked(pk, idOf(pk, i)) != null) {
- picked.append(a, (rowAt(p, pk, a, i) catch return).target) catch return;
+ const picked = pickedRows(p, pk, a) catch return;
+ if (picked.len == 0) return;
+ // Walk: the first now, the others queued for C-i.
+ pk.queue.clearRetainingCapacity();
+ pk.queue_bytes.clearRetainingCapacity();
+ pk.queue_at = 0;
+ if (how == .queue) for (picked[1..]) |t| switch (t) {
+ .place => |at| {
+ const q: Queued = .{ .path = @intCast(pk.queue_bytes.items.len), .len = @intCast(@min(at.path.len, std.math.maxInt(u16))), .line = std.math.lossyCast(u32, at.at.line), .col = std.math.lossyCast(u32, at.at.col) };
+ pk.queue_bytes.appendSlice(p.gpa, at.path[0..q.len]) catch break;
+ pk.queue.append(p.gpa, q) catch break;
+ },
+ else => {},
};
TagState.toRest(p);
const v = p.view();
const from = p.paneBySerial(pk.owner) orelse v.active;
v.active = from;
v.jumps.force = true;
- for (picked.items, 0..) |t, k| switch (t) {
+ for (picked, 0..) |t, k| switch (t) {
.none => {},
.pane => |serial| if (p.paneBySerial(serial)) |tid| {
v.active = tid;
@@ -952,7 +1010,7 @@ fn land(p: *Pardes, how: How) void {
} else {
_ = p.store.reopen(p, serial, from);
},
- .place => |at| if (k == 0 and how == .walk) {
+ .place => |at| if (k == 0 and (how == .walk or how == .queue)) {
_ = look.open(p, from, at.path, at.at, .replace);
} else if (k == 0 and how == .column) {
layout.newColumn(p, from);
@@ -961,10 +1019,234 @@ fn land(p: *Pardes, how: How) void {
defer p.exec_column = null;
pardes.tagline.exitHeader(p);
_ = look.open(p, from, at.path, at.at, .below);
- } else {
+ } else if (how != .queue) {
_ = look.open(p, from, at.path, at.at, .below);
},
};
+ if (how == .queue and pk.queue.items.len > 0) {
+ var said: Kind.Buf(64) = .{};
+ p.setMessage(.at(v.active), said.print("Walk: {d} more places here, C-i for the next", .{pk.queue.items.len}));
+ }
+}
+
+/// B3 on a picker's row (mouse.zig bandPress): Enter on it.
+pub fn landHere(p: *Pardes) void {
+ const pk = live(p) orelse return;
+ if (pk.spine == .rows) land(p, .walk);
+}
+
+/// The rows an act or Enter takes: the marked, else the current.
+fn pickedRows(p: *Pardes, pk: *const Pick, a: std.mem.Allocator) ![]Target {
+ const s = &p.view().tag_state;
+ const n = count(p, pk);
+ var picked: std.ArrayList(Target) = .empty;
+ if (n == 0) return picked.items;
+ if (pk.marks.items.len == 0) {
+ try picked.append(a, (try rowAt(p, pk, a, s.rows.at)).target);
+ } else for (0..n) |i| if (marked(pk, idOf(pk, i)) != null) {
+ try picked.append(a, (try rowAt(p, pk, a, i)).target);
+ };
+ return picked.items;
+}
+
+/// C-i past a reading pane's newest step (Jump.jumpBy, SPEC §6.4): the
+/// next place a Walk queued in it, through the list its trail holds last.
+pub fn stepQueue(p: *Pardes, id: usize) bool {
+ const pane = p.panes[id] orelse return false;
+ const t = &pane.trail;
+ var i: usize = @min(t.cur, t.n);
+ const pk = while (i > 0) {
+ i -= 1;
+ if (t.steps[i] == .list) break byId(p, t.steps[i].list.index) orelse return false;
+ } else return false;
+ if (pk.queue_at >= pk.queue.items.len) return false;
+ const q = pk.queue.items[pk.queue_at];
+ pk.queue_at += 1;
+ p.view().jumps.force = true;
+ _ = look.open(p, id, pk.queue_bytes.items[q.path..][0..q.len], .{ .line = q.line, .col = q.col }, .replace);
+ return true;
+}
+
+// ---- acts ----
+
+/// What the act step offers (SPEC §5.5): the same everywhere, but a list
+/// of panes, whose rows are no places, has Look, Copy, Keep, Drop and Del.
+const Act = struct { key: u8, word: []const u8, says: []const u8 };
+const acts = [_]Act{
+ .{ .key = 'w', .word = "Walk", .says = "here, one by one (C-i)" },
+ .{ .key = 'o', .word = "Look", .says = "open them (Enter)" },
+ .{ .key = 's', .word = "Split", .says = "each in a pane below" },
+ .{ .key = 'v', .word = "Newcol", .says = "in a new column" },
+ .{ .key = 'g', .word = "Grep", .says = "in their directory, the same pattern" },
+ .{ .key = 'e', .word = "Edit", .says = "a sam command on each line" },
+ .{ .key = 'y', .word = "Copy", .says = "the places, as text" },
+ .{ .key = 'k', .word = "Keep", .says = "the rows as a +Search" },
+ .{ .key = 'x', .word = "Drop", .says = "the picked from the list" },
+ .{ .key = 'd', .word = "Del", .says = "close those panes" },
+};
+
+fn offered(pk: *const Pick, act: Act) bool {
+ if (pk.source == .panes) return std.mem.indexOfScalar(u8, "oykxd", act.key) != null;
+ return act.key != 'd';
+}
+
+/// The act step: what it acts on (`on 2 marked`, `on core/pick.zig`),
+/// then the acts.
+fn actStep(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator) !Band.Step {
+ var rows: std.ArrayList(Band.Row) = .empty;
+ const s = &p.view().tag_state;
+ const on = if (pk.marks.items.len > 0)
+ try std.fmt.allocPrint(arena, "on {d} marked", .{pk.marks.items.len})
+ else if (count(p, pk) > 0) on: {
+ const row = try rowAt(p, pk, arena, s.rows.at);
+ break :on try std.fmt.allocPrint(arena, "on {s}", .{switch (row.target) {
+ .place => |t| relative(t.path, pk.dir.slice()),
+ else => row.text,
+ }});
+ } else "on nothing";
+ try rows.append(arena, .{ .text = on, .dim = true });
+ var k: u8 = 0;
+ for (acts) |act| if (offered(pk, act)) {
+ try rows.append(arena, .{ .text = try std.fmt.allocPrint(arena, "{c} {s: <7} {s}", .{ act.key, act.word, act.says }), .key = 1, .on = k == pk.act_at, .index = k });
+ k += 1;
+ };
+ return .{ .rows = rows.items };
+}
+
+fn actKey(p: *Pardes, pk: *Pick, k: Key) void {
+ const plain = !k.ctrl and !k.alt;
+ var n: u8 = 0;
+ for (acts) |act| n += @intFromBool(offered(pk, act));
+ if (plain and (k.cp == Key.down or k.cp == Key.up)) {
+ pk.act_at = if (k.cp == Key.down) (pk.act_at + 1) % n else (pk.act_at + n - 1) % n;
+ return;
+ }
+ var at: u8 = 0;
+ for (acts) |act| if (offered(pk, act)) {
+ if (plain and (k.cp == act.key or k.cp == Key.enter and at == pk.act_at)) return doAct(p, pk, act.key);
+ at += 1;
+ };
+ // Anything else (M-h, Left): back to the rows.
+ pk.spine = .rows;
+}
+
+/// Act `key` on the picked rows.
+fn doAct(p: *Pardes, pk: *Pick, key_: u8) void {
+ const s = &p.view().tag_state;
+ pk.spine = .rows;
+ switch (key_) {
+ 'w' => land(p, .queue),
+ 'o' => land(p, .walk),
+ 's' => land(p, .below),
+ 'v' => land(p, .column),
+ 'k' => keep(p, pk),
+ 'x' => refine(p, pk, true),
+ 'e' => {
+ pk.query.set(s.field.text());
+ s.field.clear();
+ pk.spine = .edit;
+ },
+ 'g' => {
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ const picked = pickedRows(p, pk, arena.allocator()) catch return;
+ const dir = for (picked) |t| switch (t) {
+ .place => |at| break std.Io.Dir.path.dirname(at.path) orelse pk.dir.slice(),
+ else => {},
+ } else pk.dir.slice();
+ const q = if (pk.source == .grep) arena.allocator().dupe(u8, s.field.text()) catch return else "";
+ const where = arena.allocator().dupe(u8, dir) catch return;
+ const from = p.paneBySerial(pk.owner) orelse p.view().active;
+ TagState.toRest(p);
+ open(p, from, .grep, "", "", "");
+ const grep = live(p) orelse return;
+ grep.dir.set(where);
+ p.view().tag_state.field.set(q);
+ filter(p, grep);
+ },
+ 'y' => {
+ var out: std.Io.Writer.Allocating = .init(p.gpa);
+ defer out.deinit();
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ const picked = pickedRows(p, pk, arena.allocator()) catch return;
+ for (picked) |t| switch (t) {
+ .place => |at| out.writer.print("{s}:{d}\n", .{ at.path, @max(1, at.at.line) }) catch return,
+ .pane => |serial| out.writer.print(config.pane_addr ++ "{d}\n", .{serial}) catch return,
+ .none => {},
+ };
+ p.registers.put(p.gpa, '"', out.written(), 0, 1, true) catch |err| return p.reportError(.at(p.view().active), "pick", err);
+ var said: Kind.Buf(64) = .{};
+ p.setMessage(.at(p.view().active), said.print("Copy: {d} places into the \" register", .{picked.len}));
+ },
+ 'd' => {
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ const picked = pickedRows(p, pk, arena.allocator()) catch return;
+ for (picked) |t| if (t == .pane) if (p.paneBySerial(t.pane)) |id| if (id != p.paneBySerial(pk.landing)) {
+ p.removePane(id, null) catch |err| p.reportError(.at(id), "pick", err);
+ };
+ pk.marks.clearRetainingCapacity();
+ start(p, pk);
+ filter(p, pk);
+ },
+ else => {},
+ }
+}
+
+/// Edit's Enter: its command run on each picked row's line, in the open
+/// text that shows its file (edit_cmd.zig, an undo step a line); a row
+/// whose file no pane shows is passed over, and said.
+fn editRows(p: *Pardes, pk: *Pick) void {
+ const s = &p.view().tag_state;
+ var arena = std.heap.ArenaAllocator.init(p.gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ const command = a.dupe(u8, std.mem.trim(u8, s.field.text(), " ")) catch return;
+ const picked = pickedRows(p, pk, a) catch return;
+ TagState.toRest(p);
+ if (command.len == 0) return;
+ var ran: usize = 0;
+ // From the last line up, so an edit that adds lines moves none still to come.
+ var k = picked.len;
+ while (k > 0) {
+ k -= 1;
+ const at = switch (picked[k]) {
+ .place => |t| t,
+ else => continue,
+ };
+ const id = for (p.panes, 0..) |slot, i| {
+ const tp = slot orelse continue;
+ const f = tp.file orelse continue;
+ if (f.output == null and std.mem.eql(u8, f.path, at.path)) break i;
+ } else continue;
+ @import("edit_cmd.zig").run(p, id, std.fmt.allocPrint(a, "{d} {s}", .{ @max(1, at.at.line), command }) catch return);
+ ran += 1;
+ }
+ var said: Kind.Buf(96) = .{};
+ p.setMessage(.at(p.view().active), said.print("Edit {s}: {d} of {d} lines, in open texts", .{ command[0..@min(command.len, 40)], ran, picked.len }));
+}
+
+/// A word of the picker's tag or band run (B2, exec.zig
+/// executeBuiltinLine) while it is live: an act's word acts, a source's
+/// switches to it (Grep, both, is the source); anything else is no
+/// picker's.
+pub fn execWord(p: *Pardes, txt: []const u8) bool {
+ const pk = live(p) orelse return false;
+ const word = std.mem.trim(u8, txt, " \t\n");
+ for (spine_rows) |src| if (std.mem.eql(u8, word, src.word)) {
+ switchTo(p, pk, src.source);
+ return true;
+ };
+ if (std.mem.eql(u8, word, "Jumplist")) {
+ switchTo(p, pk, .jumplist);
+ return true;
+ }
+ for (acts) |act| if (offered(pk, act) and std.mem.eql(u8, word, act.word)) {
+ doAct(p, pk, act.key);
+ return true;
+ };
+ return false;
}
fn testFile(p: *Pardes, tmp: *std.testing.TmpDir, name: []const u8, text: []const u8) ![]u8 {
@@ -1030,7 +1312,7 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the
const a = frame.allocator();
const tag = try tagOf(p, a, reader);
try std.testing.expect(std.mem.indexOf(u8, tag, " ␣ f Find pick 1/1\n") != null);
- try std.testing.expect(std.mem.indexOf(u8, tag, "│ Grep Recent Panes Symbols All Jumplist") != null);
+ try std.testing.expect(std.mem.indexOf(u8, tag, "│ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist") != null);
// The body previews the row's file, after a frame of its own.
p.update(.tick);
try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path);
@@ -1151,6 +1433,49 @@ test "Enter lands as a walk step in the reading pane; S-Enter opens below; from
try std.testing.expectEqual(npanes + 2, paneCount(p));
}
+test "M-l unrolls the act step, which says what it acts on; Copy puts the places in the register, Drop takes the picked rows out, Walk queues the rest for C-i" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "one\ntwo\nthree\nfour\n");
+ defer p.gpa.free(a_path);
+ look.lookAt(p, p.view().active, a_path);
+ const id = p.view().active;
+ const rows = "alpha.zig:1:1 one\nalpha.zig:2:1 two\nalpha.zig:3:1 three\nalpha.zig:4:1 four\n";
+ open(p, id, .list, "Refs", "", rows);
+ const pk = live(p).?;
+ settle(p);
+ p.update(.{ .key = .{ .cp = 'l', .alt = true } });
+ try std.testing.expect(pk.spine == .acts);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const band = (try Band.of(p, frame.allocator(), p.panes[id].?, id)).?;
+ try std.testing.expectEqual(@as(u8, 2), band.nsteps);
+ try std.testing.expectEqualStrings("on alpha.zig", band.steps[1].rows[0].text);
+ // y: the place copied, the act step rolled back to the rows.
+ p.update(.{ .key = .{ .cp = 'y', .text = "y" } });
+ try std.testing.expect(pk.spine == .rows);
+ // x: the current row dropped, as a refinement.
+ p.update(.{ .key = .{ .cp = 'l', .alt = true } });
+ p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 3), count(p, pk));
+ try std.testing.expectEqual(@as(u8, 1), pk.nrefined);
+ // Tab Tab: two marked; Walk lands on the first and queues the second.
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ p.update(.{ .key = .{ .cp = 'l', .alt = true } });
+ _ = frame.reset(.retain_capacity);
+ const marked_band = (try Band.of(p, frame.allocator(), p.panes[id].?, id)).?;
+ try std.testing.expectEqualStrings("on 2 marked", marked_band.steps[1].rows[0].text);
+ p.update(.{ .key = .{ .cp = 'w', .text = "w" } });
+ try std.testing.expect(live(p) == null);
+ try std.testing.expectEqual(@as(i32, 1), p.panes[p.view().active].?.body.cur_row);
+ try std.testing.expectEqual(@as(usize, 1), pk.queue.items.len);
+}
+
test "a picker from a reading pane unrolls in that pane, its own text set aside while it previews and back on Esc" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
defer p.deinit();