From 9d7f1c626687454cd2d8431aa8f6c905efd7ce97 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 21:10:48 -0300 Subject: 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Pick.zig | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- core/builtins.zig | 9 ++++++ core/lsp/Ask.zig | 6 ++++ 3 files changed, 107 insertions(+), 3 deletions(-) (limited to 'core') 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(); diff --git a/core/builtins.zig b/core/builtins.zig index 589915c2..52e4ce1d 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -1801,6 +1801,7 @@ pub const Grep = struct { /// stays, its count 0; the write hears `not found`. fn search(c: Ctx, source: panes.Query.Source, miss: []const u8) void { const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); + if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, if (source == .find) .find else .grep, "", pat, ""); const reused = panes.Query.ofOwner(c.p, c.pane.serial) != null; panes.Query.open(c.p, c.id, source, pat, pat.len == 0); if (pat.len == 0 or !c.p.fs.serving) return; @@ -1823,6 +1824,11 @@ pub const Search = struct { pub fn run(c: Ctx) void { const line = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); const asked = panes.Query.parse(line) orelse panes.Query.parse(std.mem.concat(c.p.scratch.allocator(), u8, &.{ "/", line }) catch return).?; + // `SPC b b`, `SPC s s`, `SPC /` and the like: a picker in the tag. + if (pardes.Pick.asked(c.p)) switch (asked.source) { + inline .find, .grep, .recent, .panes, .symbols, .all => |s| return pardes.Pick.open(c.p, c.id, @field(pardes.Pick.Source, @tagName(s)), "", asked.pat, ""), + else => {}, + }; panes.Query.open(c.p, c.id, asked.source, asked.pat, true); } }; @@ -1844,6 +1850,7 @@ pub const Panes = struct { pub const takes_arg = true; pub const quiet = true; pub fn run(c: Ctx) void { + if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .panes, "", std.mem.trim(u8, c.arg orelse "", " \t\r\n"), ""); panes.Query.open(c.p, c.id, .panes, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true); } }; @@ -2072,6 +2079,7 @@ pub const Recent = struct { // The query pane under the pane the keyboard is in, line 1 // `Recent `, typed into; what follows the word narrows the files. if (c.p.panes[c.id] == null) return c.p.reportFailure(c.id, "Recent: open a pane to search from"); + if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .recent, "", std.mem.trim(u8, c.arg orelse "", " \t\r\n"), ""); panes.Query.open(c.p, c.id, .recent, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true); } }; @@ -2101,6 +2109,7 @@ pub const Jumplist = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.jumps_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { + if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .jumplist, "", "", ""); panes.Output.openJumps(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "jumplist", err); } }; diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig index 29d36f0a..976821d5 100644 --- a/core/lsp/Ask.zig +++ b/core/lsp/Ask.zig @@ -366,6 +366,12 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { return; } + // Symbols and diagnostics asked from the keyboard, where jumps walk: a + // picker in the tag of the pane its Enter lands in (Pick.zig). + if (pardes.Pick.asked(p)) switch (w.kind) { + .document_symbols, .workspace_symbols, .diagnostics, .workspace_diagnostics => return pardes.Pick.open(p, asked, .list, lspWord(w.kind), "", rows), + else => {}, + }; // The lists of places: into the asking text's query pane (made or // reused), line 1 their word, the places in that text its places. const listed: ?panes.Query.Source = switch (w.kind) { -- cgit v1.3