From f6f02bab7554e50241faa1a0c81517126bd06b94 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 00:21:48 -0300 Subject: Pick, Core, keys: SPC ' steps back through the kept pickers (UX DESIGN L'2, binding; the user liked L-b): Resume reopens the newest kept picker as before, and again as the next leader sequence after an Esc from the one it opened, nothing typed between, the one before it; Ctrl-o in a picker Resume opened steps to the next older kept one (its field, cursor and marks its own, where Resume opens them: Pick.resumeAt), Ctrl-i the next newer, each end said (`Resume: no picker before it: the last 8 are kept`, `Resume: the newest picker`); the head reads `Resume 2/5` before the picker's own word (`Resume 2/5 Find words`); the walk is `Pardes.resume_at` beside `picks` (0 for none, the newest 1): any other picker opened, reopened or landed ends it, and so does any key at rest but the leader and Resume's after it (Pick.keyAtRest, called beside Prompt.keyAtRest in keys.handleKey); the order is a picker's `used` (L': made, landed, or reopened by a walk, the newest the highest, Pick.touch), not its serial, and the picker the ring drops for a new one is the least used of them (Pick.rank: `used`, then the serial, for pickers a dump made before `used`); a list word naming a dropped picker says `walk: that list is gone: the last 8 are kept` (item L'1's walk passes it by); RUN (TEST FIRST): Pick.zig "SPC ' steps back through the kept pickers (UX L'2) ..." keeps three lists A, B, C and asks after each of SPC ', Esc SPC ', Ctrl-o, Ctrl-o (said: no picker before it), Ctrl-i, Ctrl-i, Esc j SPC ' (a key between: the newest again), Esc SPC ' the live picker and its head's `Resume k/3`, then Enter on B (the walk over, B the newest: SPC ' opens it as `1/3 B`), then Ctrl-o onto a list word whose picker is gone (said, passed by, the walk on to the first place): fails on L'1's tree at Pick.zig:2915 on the first SPC ' (expected `1/3 C`, the head has no Resume word), passes now; a user hit it whenever the picker wanted was not the last one; core-test 1126/1299 (173 skipped), shell-test 1347/1350 (3 skipped); load 3.9 to 4.6 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Core.zig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/Core.zig') diff --git a/core/Core.zig b/core/Core.zig index f47cc5d8..f9c4d6c9 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -413,6 +413,10 @@ stream: Stream = .{}, /// The pickers: the one live in a view's tag, and the last ones rolled /// up, which their list words and Resume reopen (Pick.zig). picks: [pardes.Pick.max_lists]?*pardes.Pick = @splat(null), +/// The kept picker Resume shows, the newest 1 (Pick.nth), 0 for none: +/// `SPC '` again after an Esc from it, nothing typed between, opens the +/// one before it, and Ctrl-o and Ctrl-i in it step through them (UX L'2). +resume_at: u8 = 0, /// The panes' `Changes` (jj.zig): what was asked of jj, and what it /// answered for each pane, by its serial: the session's, not a field of /// every pane (a digest and a rollback copy walk every pane's fields at -- cgit v1.3 From d75f8947fde8d2fa425ee0b60c7a687a0ff9f314 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 00:28:55 -0300 Subject: Pick, builtins, config, Core, docs: Lists, a picker of the kept pickers (UX DESIGN L'3, binding; the user liked L-c): `SPC f l`, the word Lists, and `'` among a picker's sources (M-h) open it from the asking pane (Source.lists; from a live picker, one of its own where that one was asked: switchTo); its rows, newest first (Pick.nth), are the kept pickers' list words, the source word, the query (refinements joined by ` | `), `cursor/matches` and `•N` when marked (Pick.wordOf), each with where it last landed at its right, dim, `@p2 › words.zig:16` (Pick.landed, written by land); the body previews the picker's current row as any place (its row's target); the band's second step, a doc, shows that picker's rows around its cursor, which is marked `▶`, read only (Pick.listedStep); Enter (and B3 on a row) reopens that picker as it was left, where Lists was asked from, the newest now (Pick.reopenListed); Esc to rest; no acts and no sources in it (head `⏎ reopen it · esc`; execWord passes it by); Lists itself is never kept: Pardes.picks has one more slot, Lists takes the one Lists had or a free one, never drops a kept picker for its room, is never in Resume's order, in Lists' rows or the count of the kept (Pick.make, nth, nkept); Resume's doc says its walk; docs: the reference's "Back to a picker" (the three ways and what Ctrl-o, Resume and Lists do), the cheatsheet's Ctrl-o row and `SPC f l`, `SPC '`; builtins-tui.json regenerated (Lists, Resume); RUN (TEST FIRST): Pick.zig "Lists (UX L'3) ..." keeps eight lists (G left on its second row, H landed), opens Lists and asks that none was dropped and it is none of the kept, its rows `H 1/2` .. `A 1/2` newest first with H's `@pN › alpha.zig:2`, on G the body previewing beta.zig at line 2 and its rows beside with the second marked, Enter reopening G on its second row as the newest, a ninth picker dropping the oldest kept and never for Lists' room, and M-h `'` from a live J opening Lists with J first: does not build on L'2's tree (no Lists source), passes now; goldens: find (the SPC f level shows `l Lists`); with L'1 and L'2 under it: core-test 1127/1300 (173 skipped; the docs test caught `#key("Backspace")` and `#key("'")`, which name no binding: written as text, passing alone), shell-test 1348/1351 (3 skipped, the same), pane-test 183/184, behaviour-test 280/280 and --replay 280/280, process-test 2 of 147 failed before find moved (find; ttyhelp the placeholder), term-test 17/17, kitty-test 45/45; the dump fuzz (Step.search, Pick.used, landed, walking, Pardes.resume_at, picks one more) at 40,000 join seeds twice and 1,779 image seeds 13/13; the soak replicas --clients 5 --rtt 30,80,207: diverged 0, unequal 0, quiet checks 351/0 481/0 564/0, stops not on may_wait 0, the corpus 22 of 22 scenes the same, no leak; the frame and perf gate on the stack's top; load 2.4 to 13.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Core.zig | 5 +- core/Pick.zig | 182 +++++++++++++++++++++++++++++++++++++++++---- core/builtins.zig | 16 +++- core/config.zig | 1 + docs/typ/builtins-tui.json | 3 +- docs/typ/cheatsheet.typ | 4 +- docs/typ/reference.typ | 21 ++++++ test/snapshots/find.golden | 2 +- 8 files changed, 212 insertions(+), 22 deletions(-) (limited to 'core/Core.zig') diff --git a/core/Core.zig b/core/Core.zig index f9c4d6c9..cbcf4324 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -411,8 +411,9 @@ pipe: Pipe = .{}, /// A query pane's Grep, and its Find's listing, on a worker (Stream.zig). stream: Stream = .{}, /// The pickers: the one live in a view's tag, and the last ones rolled -/// up, which their list words and Resume reopen (Pick.zig). -picks: [pardes.Pick.max_lists]?*pardes.Pick = @splat(null), +/// up, which their list words, Resume and Lists reopen (Pick.zig); Lists +/// itself in the one more, never kept. +picks: [pardes.Pick.max_lists + 1]?*pardes.Pick = @splat(null), /// The kept picker Resume shows, the newest 1 (Pick.nth), 0 for none: /// `SPC '` again after an Esc from it, nothing typed between, opens the /// one before it, and Ctrl-o and Ctrl-i in it step through them (UX L'2). diff --git a/core/Pick.zig b/core/Pick.zig index 85c16a69..0c6b1c68 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -54,8 +54,9 @@ const Key = pardes.Key; /// answer, SPC e's places), titled by their word, the messages' history /// (SPC h m), the themes (SPC t t, the window wearing the one under /// the cursor), and a language server's code actions for the caret's place -/// (SPC l a, the body showing the one under the cursor as its edit). -pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, messages, themes, actions }; +/// (SPC l a, the body showing the one under the cursor as its edit), and +/// the kept pickers (Lists, UX L'3). +pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, messages, themes, actions, lists }; /// Each source's word in the tag and its key cells (`␣ f Find`); a /// source whose Backspace leaves it (`back`) goes back to the SPC level of @@ -72,9 +73,11 @@ const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8 .messages = .{ .word = "Messages", .keys = "h" }, .themes = .{ .word = "Themes", .keys = "t" }, .actions = .{ .word = "Actions", .keys = "la" }, + .lists = .{ .word = "Lists", .keys = "f" }, }); -/// The pickers kept after they roll up, for their list words and Resume. +/// The pickers kept after they roll up, for their list words, Resume and +/// Lists (Lists itself never one of them: Pardes.picks has one more). pub const max_lists = 8; /// Refinements a picker stacks (C-SPC). pub const max_refine = 3; @@ -147,6 +150,8 @@ act_at: u8 = 0, queue: std.ArrayList(Queued) = .empty, queue_bytes: std.ArrayList(u8) = .empty, queue_at: u32 = 0, +/// Where it last landed, `@p2 › words.zig:16` (Lists' meta, UX L'3). +landed: Kind.Buf(80) = .{}, /// Where it stands among the kept pickers, the newest the highest /// (`touch`): Resume's order (`nth`), and the oldest goes for a new one. used: u32 = 0, @@ -232,14 +237,23 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] /// A new picker in the ring, the oldest kept one dropped for it. fn make(p: *Pardes, source: Source) !*Pick { var slot: ?usize = null; - for (p.picks, 0..) |s, i| if (s == null) { + // Lists is never kept (UX L'3): the one it had goes, and it drops none + // of the kept for its room. + for (p.picks, 0..) |s, i| if (s) |pk| if (source == .lists and pk.source == .lists) { + pk.deinit(p.gpa); + p.gpa.destroy(pk); + p.picks[i] = null; + slot = i; + break; + }; + if (slot == null and (source == .lists or nkept(p) < max_lists)) for (p.picks, 0..) |s, i| if (s == null) { slot = i; break; }; if (slot == null) { // The oldest not live. var oldest: ?usize = null; - for (p.picks, 0..) |s, i| if (s) |pk| if (!pk.unrolled and (oldest == null or rank(pk) < rank(p.picks[oldest.?].?))) { + for (p.picks, 0..) |s, i| if (s) |pk| if (!pk.unrolled and pk.source != .lists and (oldest == null or rank(pk) < rank(p.picks[oldest.?].?))) { oldest = i; }; const i = oldest orelse return error.NoPickerSlots; @@ -277,7 +291,7 @@ fn nth(p: *const Pardes, k: usize) ?*Pick { var found: ?*Pick = null; for (0..k) |_| { found = null; - for (p.picks) |slot| if (slot) |pk| if (rank(pk) < below and (found == null or rank(pk) > rank(found.?))) { + for (p.picks) |slot| if (slot) |pk| if (pk.source != .lists and rank(pk) < below and (found == null or rank(pk) > rank(found.?))) { found = pk; }; below = rank(found orelse return null); @@ -285,10 +299,12 @@ fn nth(p: *const Pardes, k: usize) ?*Pick { return found; } -/// The pickers kept. +/// The pickers kept: not Lists. fn nkept(p: *const Pardes) usize { var n: usize = 0; - for (p.picks) |slot| n += @intFromBool(slot != null); + for (p.picks) |slot| if (slot) |pk| { + n += @intFromBool(pk.source != .lists); + }; return n; } @@ -376,6 +392,13 @@ fn start(p: *Pardes, pk: *Pick) void { addRows(p, pk, out.written()); }, .list => addRows(p, pk, pk.rows), + // The kept pickers, newest first, each by its list word. + .lists => for (1..max_lists + 1) |k| { + const kp = nth(p, k) orelse break; + var word: Kind.Buf(Trail.max_text) = .{}; + const text = wordOf(p, kp, &word); + pk.names.add(p.gpa, text, 0, text.len, 0, kp.id) catch return; + }, .messages => { var out: std.Io.Writer.Allocating = .init(p.gpa); defer out.deinit(); @@ -560,7 +583,7 @@ const Target = union(enum) { none, place: struct { path: []const u8, at: look.Sp /// `arena`. const Row = struct { text: []const u8, key: u8 = 0, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none, meta: []const u8 = "" }; -fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { +fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.mem.Allocator.Error!Row { const dir = pk.dir.slice(); if (!fuzzy(pk) and pk.source == .all) { var order: [pardes.MAX_PANES]usize = undefined; @@ -626,6 +649,14 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { const f = owner.file orelse return row; row.target = .{ .place = .{ .path = f.path, .at = .{ .line = cand.ref } } }; }, + // A kept picker: where it last landed, its current row's place the + // preview (UX L'3). + .lists => { + const kp = byId(p, cand.ref) orelse return row; + row.meta = kp.landed.slice(); + const n = count(p, kp); + if (n > 0) row.target = (try rowAt(p, kp, arena, @min(kp.at, n - 1))).target; + }, // The theme in use says so, whichever the window wears (POLISH 12). .themes => if (p.custom_theme == null and cand.ref == p.settings.theme) { row.meta = "in use"; @@ -707,10 +738,15 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { if (n == 0) try text.append(arena, '0') else try text.print(arena, "{d}/{d}", .{ s.rows.at + 1, n }); if (pk.marks.items.len > 0) try text.print(arena, " •{d}", .{pk.marks.items.len}); if (pk.names.busy() or p.stream.busyFor(pk.id)) try text.appendSlice(arena, " ⋯"); - // Themes and actions have no acts and no other sources: no second row. - if (pk.source == .themes or pk.source == .actions) { + // Themes, actions and Lists have no acts and no other sources: no + // second row. + if (pk.source == .themes or pk.source == .actions or pk.source == .lists) { const hints = text.items.len; - try b.styled(if (pk.source == .themes) "⏎ wear it · esc" else "⏎ or 1-9 apply it · esc", .dim); + try b.styled(switch (pk.source) { + .themes => "⏎ wear it · esc", + .lists => "⏎ reopen it · esc", + else => "⏎ or 1-9 apply it · esc", + }, .dim); try b.right(counted, hints); var h = b.done(); h.caret = caret; @@ -732,7 +768,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const nacts = nw; offer[nw] = "|"; nw += 1; - inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != .actions and src != pk.source) { + inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != .actions and src != .lists and src != pk.source) { offer[nw] = words.get(src).word; nw += 1; }; @@ -778,8 +814,9 @@ 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 or pk.spine == .acts) 2 else 1); + const out = try arena.alloc(Band.Step, if (pk.spine == .sources or pk.spine == .acts or pk.source == .lists) 2 else 1); if (pk.spine == .acts) out[1] = try actStep(p, pk, arena); + if (pk.source == .lists) out[1] = try listedStep(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 }; @@ -825,6 +862,18 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { return out; } +/// Lists' second step (UX L'3): the kept picker under its cursor, its +/// rows around its own cursor, which is marked `▶`; read, never a list. +fn listedStep(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator) !Band.Step { + const kp = byId(p, @intCast(refAt(p, pk) orelse return .{ .doc = true })) orelse return .{ .doc = true }; + const n = count(p, kp); + const lo = if (kp.at < Band.Cursor.shown) 0 else kp.at + 1 - Band.Cursor.shown; + const hi = @min(n, lo + Band.Cursor.shown); + const rows = try arena.alloc(Band.Row, hi -| lo); + for (rows, lo..) |*row, i| row.* = .{ .text = try std.fmt.allocPrint(arena, "{s}{s}", .{ if (i == kp.at) "▶ " else " ", (try rowAt(p, kp, arena, i)).text }) }; + return .{ .rows = rows, .doc = true }; +} + // ---- the preview ---- /// The line (from 0) pane `pane`'s body lands the live picker's cursor row @@ -854,7 +903,7 @@ pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usi /// previewing. pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize { const pk = live(p) orelse return null; - if (!pk.previews or pk.source == .themes or pk.source == .actions) return null; + if (!pk.previews or pk.source == .themes or pk.source == .actions or pk.source == .lists) return null; if (pk.landing == pk.owner) { w.writeAll("⏎ lands here") catch return null; } else { @@ -1170,7 +1219,8 @@ pub fn key(p: *Pardes, k: Key) void { // Themes: Enter wears the one under the cursor; actions: Enter, or an // action's digit with the field empty, applies it; the rows and the // field. - if (pk.source == .themes or pk.source == .actions) { + if (pk.source == .themes or pk.source == .actions or pk.source == .lists) { + if (plain and k.cp == Key.enter and pk.source == .lists) return reopenListed(p, pk); if (plain and k.cp == Key.enter and pk.source == .themes) { const at = refAt(p, pk) orelse return; TagState.toRest(p); @@ -1246,6 +1296,7 @@ const spine_rows = [_]struct { key: u8, word: []const u8, source: ?Source }{ .{ .key = 'b', .word = "Panes", .source = .panes }, .{ .key = 's', .word = "Symbols", .source = .symbols }, .{ .key = '/', .word = "All", .source = .all }, + .{ .key = '\'', .word = "Lists", .source = .lists }, .{ .key = '?', .word = "Help", .source = null }, }; @@ -1261,6 +1312,13 @@ fn switchTo(p: *Pardes, pk: *Pick, source: ?Source) void { p.view().tag_state.field.set(query.slice()); return TagState.filter(p); }; + // Lists is a picker of the kept ones, this one among them: one of its + // own, from where this one was asked (UX L'3). + if (to == .lists) { + const from = p.paneBySerial(pk.owner) orelse p.view().active; + TagState.toRest(p); + return open(p, from, to, "", "", ""); + } if (p.stream.target == pk.id) _ = p.stream.stop(); for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa); for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(p.gpa); @@ -1505,6 +1563,9 @@ fn land(p: *Pardes, wanted: How) void { _ = look.open(p, from, at.path, at.at, .below); }, }; + if (picked[0] == .place) if (p.panes[v.active]) |at| if (at.file) |f| { + _ = pk.landed.print(config.pane_addr ++ "{d} › {s}:{d}", .{ at.serial, std.Io.Dir.path.basename(f.path), at.body.cur_row + 1 }); + }; 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})); @@ -1659,9 +1720,22 @@ pub fn keyAtRest(p: *Pardes, k: Key) void { /// 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.source == .lists) return reopenListed(p, pk); if (pk.spine == .rows) land(p, .walk); } +/// Enter in Lists (UX L'3): the kept picker under its cursor unrolled again +/// as it was left, where Lists was asked from, and the newest now. +fn reopenListed(p: *Pardes, pk: *Pick) void { + const kp = byId(p, @intCast(refAt(p, pk) orelse return)) orelse return; + const from = p.paneBySerial(pk.owner) orelse p.view().active; + TagState.toRest(p); + touch(p, kp); + hostIn(p, kp, from) catch |err| return p.reportError(.at(from), "Lists", err); + unroll(p, kp, kp.query.slice()); + unrollRows(p, kp); +} + /// 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; @@ -1860,6 +1934,8 @@ fn editRows(p: *Pardes, pk: *Pick) void { /// picker's. pub fn execWord(p: *Pardes, txt: []const u8) bool { const pk = live(p) orelse return false; + // Lists offers no acts and no sources (UX L'3). + if (pk.source == .lists) 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); @@ -3000,3 +3076,77 @@ test "SPC ' steps back through the kept pickers (UX L'2): again after an Esc, no try std.testing.expectEqualStrings("base.zig", std.Io.Dir.path.basename(p.panes[p.view().active].?.file.?.path)); try std.testing.expectEqual(@as(u8, 0), p.panes[p.view().active].?.trail.cur); } + +test "Lists (UX L'3): a picker of the kept pickers, newest first, each its list word and where it last landed; the body previews the one under the cursor at its current row, its rows beside, its cursor's marked; Enter reopens it as it was left, the newest now; Lists is never kept and drops none of the eight for its room" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .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\n"); + defer p.gpa.free(a_path); + const b_path = try testFile(p, &tmp, "beta.zig", "b1\nb2\n"); + defer p.gpa.free(b_path); + const base = try p.setTestFile("text\n"); + p.gpa.free(base.file.?.path); + base.file.?.path = try testFile(p, &tmp, "base.zig", "text\n"); + const rows = try std.fmt.allocPrint(p.gpa, "{s}:2:1 two\n{s}:2:1 b2\n", .{ a_path, b_path }); + defer p.gpa.free(rows); + // Eight kept: A to F, G left on its second row, H landed, the newest. + for ("ABCDEFG") |c| { + open(p, p.view().active, .list, &[_]u8{c}, "", rows); + if (c == 'G') p.update(.{ .key = .{ .cp = Key.down } }); + p.update(.{ .key = .{ .cp = Key.escape } }); + } + open(p, p.view().active, .list, "H", "", rows); + p.update(.{ .key = .{ .cp = Key.enter } }); + p.sync(); + const at = p.view().active; + var ids: [max_lists]u32 = undefined; + for (&ids, 1..) |*id, k| id.* = nth(p, max_lists + 1 - k).?.id; + exec.runBuiltin(p, .Lists, at, "", null); + const lists = live(p).?; + try std.testing.expectEqual(Source.lists, lists.source); + // None dropped for it, and it is none of the kept. + try std.testing.expectEqual(@as(usize, max_lists), nkept(p)); + for (ids) |id| try std.testing.expect(byId(p, id) != null); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + try std.testing.expectEqual(@as(usize, max_lists), count(p, lists)); + var buf: [64]u8 = undefined; + for ("HGFEDCBA", 0..) |c, i| { + const row = try rowAt(p, lists, a, i); + try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{c} {d}/2", .{ c, @as(u8, if (c == 'G') 2 else 1) }), row.text); + if (c == 'H') try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "@p{d} › alpha.zig:2", .{p.panes[at].?.serial}), row.meta); + } + // On G: the body previews its current row, beta.zig's line 2; its rows + // beside, its cursor's marked. + p.update(.{ .key = .{ .cp = Key.down } }); + settle(p); + const host = p.panes[p.paneBySerial(lists.landing).?].?; + try std.testing.expectEqualStrings(b_path, host.file.?.path); + try std.testing.expectEqual(@as(i32, 1), host.body.cur_row); + const band = try steps(p, a); + try std.testing.expect(band.len == 2 and band[1].doc and band[1].rows.len == 2); + try std.testing.expect(std.mem.startsWith(u8, band[1].rows[1].text, "▶ ") and std.mem.startsWith(u8, band[1].rows[0].text, " ")); + // Enter: G as it was left, the newest now; Lists rolled up. + p.update(.{ .key = .{ .cp = Key.enter } }); + const g = live(p).?; + try std.testing.expectEqualStrings("G", g.word.slice()); + try std.testing.expectEqual(@as(u16, 1), p.view().tag_state.rows.at); + try std.testing.expect(nth(p, 1).? == g); + p.update(.{ .key = .{ .cp = Key.escape } }); + // A ninth picker drops the oldest kept, never for Lists' room. + open(p, p.view().active, .list, "I", "", rows); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(@as(usize, max_lists), nkept(p)); + try std.testing.expect(byId(p, ids[0]) == null and byId(p, ids[1]) != null); + // `'` among a picker's sources (M-h): Lists, from where it was asked. + open(p, p.view().active, .list, "J", "", rows); + p.update(.{ .key = .{ .cp = 'h', .alt = true } }); + p.update(.{ .key = .{ .cp = '\'', .text = "'" } }); + try std.testing.expectEqual(Source.lists, live(p).?.source); + try std.testing.expectEqualStrings("J 1/2", (try rowAt(p, live(p).?, a, 0)).text); + p.update(.{ .key = .{ .cp = Key.escape } }); +} diff --git a/core/builtins.zig b/core/builtins.zig index 7aaeee40..829935c7 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -2045,13 +2045,27 @@ pub const Forward = struct { /// Reopen the last picker as it was: its rows, marks, cursor and query. /// /// In the tag of the pane its Enter lands in from this one: this pane if it -/// reads, else its reader. `SPC '`. +/// reads, else its reader. `SPC '`; again after its Esc, nothing typed +/// between, the one before it; Ctrl-o and Ctrl-i in it, the older and newer. pub const Resume = struct { pub fn run(c: Ctx) void { pardes.Pick.resumeFrom(c.p, c.id); } }; +/// Pick from the last pickers kept, newest first: Enter reopens one as it was left. +/// +/// A row each: its source, query, cursor and marks, where it last landed at +/// its right. The body previews its current row; beside the rows, its +/// first rows. `SPC f l`, or `'` in a picker's sources (M-h). +pub const Lists = struct { + pub const scope: Scope = .session; + pub fn run(c: Ctx) void { + if (c.p.panes[c.id] == null) return c.p.reportFailure(c.id, "Lists: open a pane to pick from"); + pardes.Pick.open(c.p, c.id, .lists, "", "", ""); + } +}; + /// Keep this pane: a reading pane, which a jump steps, is held from now on. /// /// Its walk leaves its tag (its places, its owner): the next jump from its diff --git a/core/config.zig b/core/config.zig index d916b677..03cb6044 100644 --- a/core/config.zig +++ b/core/config.zig @@ -148,6 +148,7 @@ pub const leader_path = paths: { .Forward = "ji", .Keep = "jk", .Resume = "'", + .Lists = "fl", .Last = "jj", .Jumplist = "jl", .History = "fh", diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index 9d726dc5..91757231 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -59,6 +59,7 @@ {"name": "Kill", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Stop the commands pardes started that are still running.", "text": "Stop the commands pardes started that are still running.\nThey are the lines pardes typed into a terminal (from an exec, a middle click, a pty/run) and its command panes. Bare, every one; `Kill make ls`, those whose line starts with one of the words. Each gets SIGTERM: a command pane's whole command, a terminal's foreground job, never its shell, which stays."}, {"name": "Last", "leader": "SPC j j", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Go back to the last place jumped from in another pane.", "text": "Go back to the last place jumped from in another pane.\nWith none, to the pane beside this one."}, {"name": "Left", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane, or column tag, to the left.", "text": "Move the keyboard to the pane, or column tag, to the left."}, + {"name": "Lists", "leader": "SPC f l", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Pick from the last pickers kept, newest first: Enter reopens one as it was left.", "text": "Pick from the last pickers kept, newest first: Enter reopens one as it was left.\nA row each: its source, query, cursor and marks, where it last landed at its right. The body previews its current row; beside the rows, its first rows. `SPC f l`, or `'` in a picker's sources (M-h)."}, {"name": "LocationsConfig", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Set how a list's location rows are drawn: `LocationsConfig layout:inline context:2`.", "text": "Set how a list's location rows are drawn: `LocationsConfig layout:inline context:2`.\nIts fields: `context:` around each, `tscontext:on|off`, `tslocations:on|off`, `layout:inline|stacked`; those not given stay. Bare, it shows them in a +LocationsConfig."}, {"name": "Look", "leader": null, "also": ["enter", "right-click"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Look at its argument as B3 does: open the file or address it names, else find the word.", "text": "Look at its argument as B3 does: open the file or address it names, else find the word.\n`Look notes.txt:12` opens the file at line 12, or goes to the pane already showing it; an address may be a line, `:12:5`, `/re/`, a directory (a pane listing it) or a URL (the browser, by a plumbing rule). A relative path is found in the directory of the pane looked from, then of each pane on the jump list. Bare (Enter): the selection, else what is under the cursor."}, {"name": "LookNext", "leader": "SPC j n", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select the next thing a Look would open: a place in a list, a word that names a file.", "text": "Select the next thing a Look would open: a place in a list, a word that names a file.\nThe walk goes on through the panes in order, the keyboard with it; Enter opens what it selected."}, @@ -87,7 +88,7 @@ {"name": "Rename", "leader": "SPC l r", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Rename the symbol under the cursor to its argument, wherever the language server finds it.", "text": "Rename the symbol under the cursor to its argument, wherever the language server finds it.\nBare, it asks for the new name. Within this file it is done at once, saying how many places changed; one that reaches other files changes nothing and lists its edits in a +Search to look over."}, {"name": "Repl", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Bind this terminal as a language's REPL: an exec on that language's files is typed into it.", "text": "Bind this terminal as a language's REPL: an exec on that language's files is typed into it.\n`Repl python` binds it (the language named as a code fence names it: `py`, `Python`, `sh`); `Repl -` unbinds it; bare, it says what it is bound as. An exec made on the body of a file in that language (a middle click, the execute key, a single word like `ls` as much as a selection), and one made on this terminal's own body, is typed into it (bracketed paste if its program asked for that, else line by line, then Enter) instead of run. With several bound for a language, the exec asks which.\nStill commands, whatever is bound: a word in a tag, `Exec `, a ctl line, and a command word @`cmd` in the text, looked at or clicked."}, {"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump.", "text": "Replace every pane with those of a dump.\n`Restore