summaryrefslogtreecommitdiff
path: root/core/Pick.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 21:10:48 -0300
committerGabriel Schneider <[email protected]>2026-11-24 21:10:58 -0300
commit9d7f1c626687454cd2d8431aa8f6c905efd7ce97 (patch)
tree9a2c82edc4d7faaf70119f48f101bcfeaf5b2470 /core/Pick.zig
parent3621482c586b1d0d3601a1668a307918f1faea93 (diff)
downloadpardes-9d7f1c626687454cd2d8431aa8f6c905efd7ce97.tar.gz
pardes-9d7f1c626687454cd2d8431aa8f6c905efd7ce97.zip
Pick: the entry points open a picker in the tag (walk UI, pick-ui SPEC.md §14.3 phase 4, item 5 of line D): in a session whose jumps walk, from the keyboard or a click (Pick.asked: never a 9P script's, which keeps the query pane whose rows it reads back and whose `not found` it hears), Find and Grep (`SPC f f`, `SPC f g`, their words), Recent (`SPC f r`), Search's sources (`SPC b b` Panes, `SPC s s` Symbols, `SPC /` All), Panes, Jumplist (`SPC j l`) and the language server's symbols and diagnostics (`SPC l s`, `l S`, `l d`, `l D`: lsp/Ask.zig, a list picker titled by its word) unroll in the tag of the pane their Enter lands in; `Jumps new-pane` (still the default) keeps today's query pane and +Jumps, so no golden moves; `/` in a body stays today's; two fixes to the items before: the band is as tall as its second step (the acts and what they act on, the sources), and with the preview off (M-p) no frame is asked for it (Pick.busy spun every frame); test/perf.zig `--pick`: a key in a Find of 50,000 paths and its frame, the frames after it while the names are scored, a cursor move over files and the frame after it that loads the preview, instructions and time; TEST FIRST: Pick.zig "pick-ui §14.3 phase 4: SPC f f from a held pane opens in its reader and Esc removes it; from a reading pane it unrolls there; Enter lands as a step leaving the list word; n walks; a Look on the word reopens it with its cursor and marks"; core-test 0 failed; pane-test 182/184 and behaviour-test (and --replay) 274/277, process-test 5 of 146 failed: all the base's (A's tests not updated in this base: Help's +Help, window mode, a PDF's SPC; the goldens find, tagnav, builtins, leader, ttyhelp of A's report), shell-test, term-test, kitty-test pass
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Pick.zig')
-rw-r--r--core/Pick.zig95
1 files changed, 92 insertions, 3 deletions
diff --git a/core/Pick.zig b/core/Pick.zig
index 372ff139..7913a7e0 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -60,7 +60,7 @@ const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8
.symbols = .{ .word = "Symbols", .keys = "s" },
.all = .{ .word = "All", .keys = "" },
.jumplist = .{ .word = "Jumplist", .keys = "j" },
- .list = .{ .word = "List", .keys = "" },
+ .list = .{ .word = "List", .keys = "l" },
});
/// The pickers kept after they roll up, for their list words and Resume.
@@ -143,6 +143,14 @@ pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void {
gpa.free(pk.rows);
}
+/// Whether a search a builtin asks for from pane `id` is a picker in the
+/// tag (SPEC §14.3 phase 4): in a session whose jumps walk, from the
+/// keyboard or a click, never a script's (a 9P write's: the query pane,
+/// whose rows it reads back, and whose `not found` it hears).
+pub fn asked(p: *const Pardes) bool {
+ return p.settings.jumps == .walk and !p.fs.serving;
+}
+
/// Picker `id`, kept or live.
pub fn byId(p: *const Pardes, id: u32) ?*Pick {
if (id == 0) return null;
@@ -374,7 +382,7 @@ pub fn produceAll(p: *Pardes, tick: bool) void {
/// The frames a live picker still owes: scoring, a preview (nextWake's).
pub fn busy(p: *const Pardes) bool {
for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) {
- if (pk.names.busy() or pk.shown != p.view().tag_state.rows.at) return true;
+ if (pk.names.busy() or (pk.previews and pk.shown != p.view().tag_state.rows.at)) return true;
};
return false;
}
@@ -562,7 +570,17 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
pub fn bandRows(p: *const Pardes) u16 {
const pk = live(p) orelse return 0;
const have = if (!fuzzy(pk)) Band.Cursor.shown else pk.names.cands.items.len;
- return @intCast(@max(1, @min(Band.Cursor.shown, have)));
+ const rows: usize = @max(1, @min(Band.Cursor.shown, have));
+ // Its second step's rows too: the sources, the acts and what they act on.
+ return @intCast(switch (pk.spine) {
+ .sources => @max(rows, spine_rows.len),
+ .acts => acts: {
+ var n: usize = 1;
+ for (acts) |act| n += @intFromBool(offered(pk, act));
+ break :acts @max(rows, n);
+ },
+ .rows, .edit => rows,
+ });
}
/// The band's steps: the rows around the cursor.
@@ -1498,6 +1516,10 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and
try std.testing.expectEqualStrings("alpha", s.field.text());
settle(p);
try std.testing.expectEqual(@as(usize, 3), count(p, pk));
+ // M-p: the preview off, and no frame asked for it.
+ p.update(.{ .key = .{ .cp = 'p', .alt = true } });
+ try std.testing.expect(!pk.previews and !busy(p));
+ p.update(.{ .key = .{ .cp = 'p', .alt = true } });
// M-h r: Recent, the query kept.
p.update(.{ .key = .{ .cp = 'h', .alt = true } });
try std.testing.expect(pk.spine == .sources);
@@ -1568,6 +1590,8 @@ test "M-l unrolls the act step, which says what it acts on; Copy puts the places
settle(p);
p.update(.{ .key = .{ .cp = 'l', .alt = true } });
try std.testing.expect(pk.spine == .acts);
+ // The band as tall as the acts and what they act on, the list's rows fewer.
+ try std.testing.expectEqual(@as(u16, 10), bandRows(p));
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const band = (try Band.of(p, frame.allocator(), p.panes[id].?, id)).?;
@@ -1655,6 +1679,71 @@ test "after Enter the list is a word in the reader's trail: n and N walk its row
p.update(.{ .key = .{ .cp = Key.escape } });
}
+test "pick-ui §14.3 phase 4: SPC f f from a held pane opens in its reader and Esc removes it; from a reading pane it unrolls there; Enter lands as a step leaving the list word; n walks; a Look on the word reopens it with its cursor and marks" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ p.stream.engine = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "pick.zig", "const pick = 1;\n");
+ defer p.gpa.free(a_path);
+ const b_path = try testFile(p, &tmp, "pick_test.zig", "test {}\n");
+ defer p.gpa.free(b_path);
+ const c_path = try testFile(p, &tmp, "other.zig", "x\n");
+ defer p.gpa.free(c_path);
+ _ = try p.setTestFile("held\n");
+ const held = p.view().active;
+ Trail.keep(p.panes[held].?);
+ p.gpa.free(p.panes[held].?.file.?.path);
+ p.panes[held].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" });
+ const npanes = paneCount(p);
+ const typeIn = struct {
+ fn f(pp: *Pardes, keys: []const u8) void {
+ for (keys) |c| pp.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ }
+ }.f;
+ // SPC f f from the held pane: a reader made for it, which Esc takes.
+ typeIn(p, " ff");
+ try std.testing.expect(live(p) != null and live(p).?.made);
+ try std.testing.expectEqual(npanes + 1, paneCount(p));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expectEqual(held, p.view().active);
+ // Again, typed into: Enter lands in a reader of the held pane.
+ typeIn(p, " ffpick");
+ const pk = live(p).?;
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 2), count(p, pk));
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ p.update(.{ .key = .{ .cp = Key.up } });
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ const reader = Trail.readerOf(p, p.panes[held].?).?;
+ const t = &p.panes[reader].?.trail;
+ try std.testing.expect(t.n == 3 and t.steps[1] == .list);
+ try std.testing.expect(std.mem.startsWith(u8, t.steps[1].list.text.slice(), "Find pick 1/2 •1"));
+ const first = p.panes[reader].?.file.?.path;
+ try std.testing.expect(std.mem.eql(u8, first, a_path) or std.mem.eql(u8, first, b_path));
+ // n: the other row, in place of the step.
+ p.view().active = reader;
+ p.update(.{ .key = .{ .cp = 'n', .text = "n" } });
+ const now = Trail.readerOf(p, p.panes[held].?).?;
+ try std.testing.expect(!std.mem.eql(u8, p.panes[now].?.file.?.path, first));
+ try std.testing.expectEqual(@as(u8, 3), p.panes[now].?.trail.n);
+ // SPC f f from the reader, which reads: it unrolls in the reader itself.
+ typeIn(p, " ff");
+ try std.testing.expectEqual(@as(?usize, now), TagState.hostOf(p));
+ try std.testing.expect(!live(p).?.made);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // A Look on the list word: the list again, its cursor and its mark.
+ Trail.lookStep(p, now, 1);
+ try std.testing.expect(live(p) == pk);
+ try std.testing.expectEqual(@as(u16, 1), p.view().tag_state.rows.at);
+ try std.testing.expectEqual(@as(usize, 1), pk.marks.items.len);
+ try std.testing.expectEqualStrings("pick", p.view().tag_state.field.text());
+ p.update(.{ .key = .{ .cp = Key.escape } });
+}
+
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();