From 7e7d9569a008124cb7ea01b6720a8d5963b0a42f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 18:54:18 -0300 Subject: walk (pick-ui SPEC §2, §6.1, §6.5, item 1 of the Walk UI line B): a pane is held or reading: Pane.trail (core/Trail.zig: a fixed walk, max_steps 16 of max_text 256 bytes, its steps a union of place, owner, list, search and recipe, `cur` held by walk.zig, in the digest and the dumps) and `held`, set by Keep (a new builtin, `SPC j k`) and by any edit of the file (File.edit, Trail.edited, twins too); a reading pane (a file not held: no output, listing, pager, query or kind) shows Keep after its path in its tag and its tag in the reading tint (a new theme role tag_reading_bg, derived from the page and the search ground, acme the spec's #f3f0cc), under the new setting `Jumps walk|new-pane`, whose default is new-pane until the walk's pickers are in, so every tag, frame and golden is as before (a walk default changes 74 of 102 process goldens and 21 behaviour tests by the Keep word alone); TEST FIRST: Trail.zig "a file's pane is reading ..." and "Keep holds a reading pane ..."; draw.zig's three-row tag test reads its band through tagGround; docs/typ/builtins-tui.json refreshed; core-test 993/1159 (166 skipped), pane-test 183/184, behaviour-test 277/277 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- docs/typ/builtins-tui.json | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs') diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index a503c70d..4985fa42 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -53,6 +53,8 @@ {"name": "Joincol", "leader": "SPC c j", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Fold the keyboard's column into the one on its right, keeping its panes.", "text": "Fold the keyboard's column into the one on its right, keeping its panes.\nRefused for the last column, and where the joined column could not give each pane its tag and 2 rows."}, {"name": "JumpTrail", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A jump of the cursor leaves a short trail that fades, on or off.", "text": "A jump of the cursor leaves a short trail that fades, on or off."}, {"name": "Jumplist", "leader": "SPC j l", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "List the places jumped from in a +Jumps, each a place to go.", "text": "List the places jumped from in a +Jumps, each a place to go."}, + {"name": "Jumps", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "walk, new-pane", "doc": "A jump steps its pane or that pane's reader (walk), or opens a pane for each file (new-pane).", "text": "A jump steps its pane or that pane's reader (walk), or opens a pane for each file (new-pane)."}, + {"name": "Keep", "leader": "SPC j k", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Keep this pane: a reading pane, which a jump steps, is held from now on.", "text": "Keep this pane: a reading pane, which a jump steps, is held from now on.\nIts walk leaves its tag (its places, its owner): the next jump from its owner makes a new reader. Editing a reading pane keeps it too."}, {"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."}, -- cgit v1.3 From bdc7084e2a1480272eda770a4e20bb9783c860d3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 19:35:47 -0300 Subject: walk (pick-ui SPEC §6.6, item 6 of the Walk UI line B): `Jumps new-pane`, the default (item 1 made the setting: a Settings choice, `Jumps walk` in a tag or an init line, reported by DumpConfig), jumps exactly as before the walk: look.open runs the new-pane code it always ran, nothing reads (no Keep, no tint) and no trail is made; TEST FIRST: Trail.zig "Jumps new-pane jumps as before the walk: a new pane for a file no pane shows, under the asking one, the one showing it focused, nothing stepped"; docs/typ/builtins-gui.json refreshed for Keep and Jumps, and the builtins process golden (its Look row 4 lines down); on the stack: shell-test 1214/1217, term-test 17/17, kitty-test 45/45, behaviour-test --replay 277/277, process-test 146 less the builtins golden refreshed here, the soak (5 clients) diverged 0 unequal 0 quiet checks 595/0 corpus 22/22, the gate against tree7: unit-test 1809/1813 (no failure the base has not), frame 76 and the 8 deep-sel counts differ as main's own gate merge70-g does (load 5-9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Trail.zig | 28 ++++++++++++++++++++++++++++ docs/typ/builtins-gui.json | 2 ++ test/snapshots/builtins.golden | 4 ++-- 3 files changed, 32 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/core/Trail.zig b/core/Trail.zig index 7166d810..69f149df 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -660,3 +660,31 @@ test "closing a held pane closes its reader; a kept reader stays; typed into, a try std.testing.expect(p.paneBySerial(fresh_serial) == null); try std.testing.expect(p.panes[r] != null); } + +test "Jumps new-pane jumps as before the walk: a new pane for a file no pane shows, under the asking one, the one showing it focused, nothing stepped" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const p = f.p; + p.settings.jumps = .@"new-pane"; + var at: [64]u8 = undefined; + var open: usize = 0; + for (p.panes) |slot| open += @intFromBool(slot != null); + // From the held pane and from the reading one: a new pane each time. + f.look(f.held, "rank.zig", 12); + const rank = p.view().active; + try std.testing.expectEqualStrings("rank.zig:12", f.at(&at)); + f.look(rank, "place.zig", 8); + try std.testing.expect(p.view().active != rank and p.panes[rank] != null); + try std.testing.expectEqualStrings("place.zig:8", f.at(&at)); + // A file a pane shows: that pane, focused; nothing new, no walk. + f.look(p.view().active, "rank.zig", 30); + try std.testing.expectEqual(rank, p.view().active); + try std.testing.expectEqualStrings("rank.zig:30", f.at(&at)); + var now: usize = 0; + for (p.panes) |slot| if (slot) |pane| { + now += 1; + try std.testing.expectEqual(@as(u8, 0), pane.trail.n); + }; + try std.testing.expectEqual(open + 2, now); +} diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index 8ec78384..df2ede27 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -57,6 +57,8 @@ {"name": "Joincol", "leader": "SPC c j", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Fold the keyboard's column into the one on its right, keeping its panes.", "text": "Fold the keyboard's column into the one on its right, keeping its panes.\nRefused for the last column, and where the joined column could not give each pane its tag and 2 rows."}, {"name": "JumpTrail", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A jump of the cursor leaves a short trail that fades, on or off.", "text": "A jump of the cursor leaves a short trail that fades, on or off."}, {"name": "Jumplist", "leader": "SPC j l", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "List the places jumped from in a +Jumps, each a place to go.", "text": "List the places jumped from in a +Jumps, each a place to go."}, + {"name": "Jumps", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "walk, new-pane", "doc": "A jump steps its pane or that pane's reader (walk), or opens a pane for each file (new-pane).", "text": "A jump steps its pane or that pane's reader (walk), or opens a pane for each file (new-pane)."}, + {"name": "Keep", "leader": "SPC j k", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Keep this pane: a reading pane, which a jump steps, is held from now on.", "text": "Keep this pane: a reading pane, which a jump steps, is held from now on.\nIts walk leaves its tag (its places, its owner): the next jump from its owner makes a new reader. Editing a reading pane keeps it too."}, {"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."}, diff --git a/test/snapshots/builtins.golden b/test/snapshots/builtins.golden index e9786c8a..516bbf56 100644 --- a/test/snapshots/builtins.golden +++ b/test/snapshots/builtins.golden @@ -34,7 +34,7 @@ |30: ~ |57: +Search 1/1 Save Undock Del |58: /^ +Look -|59: @p2:220:1 Look enter, right-click +|59: @p2:224:1 Look enter, right-click == snap docs-group grid=120x67 cursor=7,10 |10: 1 pardes builtins under SPC h |12: 3 SPC h b Build @@ -59,7 +59,7 @@ |10: 1 pardes builtins under SPC h Tutor |26: +Search 1/1 Save Undock Del |27: /^ +Look -|28: @p2:220:1 Look enter, right-click +|28: @p2:224:1 Look enter, right-click |36: /tmp/pardes-snap/builtins/cwd/+Tutor Save Term Collapse Follow Del |37: 1 |38: 2 PARDES TUTOR -- cgit v1.3 From 3621482c586b1d0d3601a1668a307918f1faea93 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 20:39:07 -0300 Subject: Pick: after Enter, the list word (walk UI, pick-ui SPEC.md §5.6, §6.1-§6.3 list words and n/N, item 4 of line D): Enter rolls the list into the trail of the reading pane it landed in as one word before the place, `Find pick 3/6 •2` (its word, refinements and query, where its cursor is among its rows, its marks; Trail.through, B's Trail.zig: the list a step came through), the list keeping its rows, marks, cursor and query in the session's ring; n and N in that pane walk its rows, the newest list or search word's (normal.zig, after the text's own places: a search made since is n's), in place of the current step (Trail.replaceStep: no step pushed, a file of its own a pane in its place as a step's), its word saying where it is now; a Look on the word (Trail.lookStep's list arm) unrolls the list again in that pane's tag as it was, an Exec (execStep's) runs its source again with its query from there; Resume (`SPC '`, a new builtin, docs/typ/builtins-tui.json regenerated) reopens the last picker from the pane the keyboard is in, in the tag of the pane its Enter lands in; Enter lands from the landing pane when it reads (the owner's reader or the asker itself) and from the owner otherwise; THE FAULT IT MET (B's Trail.zig, never reached before a list word existed): Trail.wordOf returned a list's, a search's or a recipe's text out of a copy of the step made by its switch, gone at the return, so a list word drew as freed bytes; the switch takes the step's own now; TEST FIRST: Pick.zig "after Enter the list is a word in the reader's trail: n and N walk its rows in place, a Look on it reopens it with its cursor and marks, Exec runs it again, Resume reopens the last" (failed on the freed bytes first); core-test 1018/1184 (166 skipped), 0 failed 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 | 205 ++++++++++++++++++++++++++++++++++++++++++--- core/Trail.zig | 42 ++++++++-- core/builtins.zig | 10 +++ core/config.zig | 1 + core/normal.zig | 2 + docs/typ/builtins-tui.json | 1 + 6 files changed, 242 insertions(+), 19 deletions(-) (limited to 'docs') diff --git a/core/Pick.zig b/core/Pick.zig index 0f9134bb..372ff139 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -168,13 +168,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] pk.word.set(if (word.len > 0) word else words.get(source).word); pk.keys.set(words.get(source).keys); pk.dir.set(Pardes.paneDir(asker)); - pk.owner = asker.serial; pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err); - const landing = landingFor(p, from) catch |err| return p.reportError(.at(from), "pick", err); - // The keyboard stays where it was: the landing pane is the tag's host. - p.view().active = from; - pk.landing = p.panes[landing].?.serial; - pk.made = landing != from and Trail.readerOf(p, asker) != landing and !Trail.reading(p, asker); + hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "pick", err); unroll(p, pk, query); start(p, pk); filter(p, pk); @@ -206,13 +201,23 @@ fn make(p: *Pardes, source: Source) !*Pick { return pk; } -/// The pane a picker from pane `from` lands in: `from` when it reads; its -/// reader when it is held and has one; else a pane made under it as its -/// reader would be, empty until the preview fills it. +/// Picker `pk` asked from pane `from`: the pane it lands in is `from` when +/// it reads; its reader when it is held and has one; else a pane made under +/// it as its reader would be, empty until the preview fills it. The +/// keyboard stays where it was: the landing pane is the tag's host. +fn hostIn(p: *Pardes, pk: *Pick, from: usize) !void { + const asker = p.panes[from].?; + pk.owner = asker.serial; + pk.made = false; + const reader = if (Trail.reading(p, asker)) from else Trail.readerOf(p, asker); + pk.landing = p.panes[reader orelse try landingFor(p, from)].?.serial; + pk.made = reader == null; + p.view().active = from; +} + +/// A pane made under pane `from` for a picker, where its reader goes. fn landingFor(p: *Pardes, from: usize) !usize { const asker = p.panes[from].?; - if (Trail.reading(p, asker)) return from; - if (Trail.readerOf(p, asker)) |r| return r; const free = p.freeSlot() orelse return error.NoPaneSlots; const content = try p.gpa.dupe(u8, ""); errdefer p.gpa.free(content); @@ -997,9 +1002,13 @@ fn land(p: *Pardes, how: How) void { }, else => {}, }; + // A step from the pane it lands in when that reads (its owner's reader + // or itself), else from its owner, whose reader the place opens as. + const landing = if (pk.made) null else p.paneBySerial(pk.landing); TagState.toRest(p); const v = p.view(); - const from = p.paneBySerial(pk.owner) orelse v.active; + const owner = p.paneBySerial(pk.owner) orelse v.active; + const from = if (how == .walk or how == .queue) landing orelse owner else owner; v.active = from; v.jumps.force = true; for (picked, 0..) |t, k| switch (t) { @@ -1011,7 +1020,10 @@ fn land(p: *Pardes, how: How) void { _ = p.store.reopen(p, serial, from); }, .place => |at| if (k == 0 and (how == .walk or how == .queue)) { - _ = look.open(p, from, at.path, at.at, .replace); + switch (look.open(p, from, at.path, at.at, .replace)) { + .none => {}, + else => listed(p, pk), + } } else if (k == 0 and how == .column) { layout.newColumn(p, from); const c = layout.activeColumn(p) orelse continue; @@ -1029,6 +1041,113 @@ fn land(p: *Pardes, how: How) void { } } +// ---- after Enter: the list word ---- + +/// The list as its word in a trail says it (SPEC §5.6): its source, its +/// query, where its cursor is among its rows, and its marks: +/// `Find pick 3/6 •2`. +fn wordOf(p: *const Pardes, pk: *const Pick, buf: *Kind.Buf(Trail.max_text)) []const u8 { + var w: std.Io.Writer = .fixed(&buf.bytes); + w.writeAll(pk.word.slice()) catch {}; + for (pk.refined[0..pk.nrefined]) |r| w.print(" {s} |", .{r.query.slice()}) catch {}; + if (pk.query.len > 0) w.print(" {s}", .{pk.query.slice()}) catch {}; + const n = count(p, pk); + w.print(" {d}/{d}", .{ if (n == 0) 0 else pk.at + 1, n }) catch {}; + if (pk.marks.items.len > 0) w.print(" •{d}", .{pk.marks.items.len}) catch {}; + buf.len = @intCast(w.buffered().len); + return buf.slice(); +} + +/// The list rolled into the trail of the reading pane it landed in, its +/// word before the place: the list `n` and `N` walk there. +fn listed(p: *Pardes, pk: *const Pick) void { + const pane = p.panes[p.view().active] orelse return; + if (!Trail.reading(p, pane)) return; + var w: Trail.Word = .{ .index = pk.id }; + _ = wordOf(p, pk, &w.text); + Trail.through(&pane.trail, .{ .list = w }); +} + +/// `n` and `N` in a reading pane whose trail's newest list or search word +/// is a list's: its next or previous row in place of the current step +/// (Trail.replaceStep), its word saying where it is now. False when there +/// is no list for them to walk (normal.zig: the search's then). +pub fn walkList(p: *Pardes, id: usize, forward: bool) bool { + const pane = p.panes[id] orelse return false; + if (!Trail.reading(p, pane)) return false; + const t = &pane.trail; + var i: usize = @min(t.cur, t.n); + while (i > 0) { + i -= 1; + switch (t.steps[i]) { + .list => break, + .search => return false, + else => {}, + } + } else return false; + const pk = byId(p, t.steps[i].list.index) orelse return false; + const n = count(p, pk); + if (n == 0) return false; + if (if (forward) pk.at + 1 >= n else pk.at == 0) { + p.setMessage(.at(id), if (forward) "n: the list's last row" else "N: the list's first row"); + return true; + } + pk.at = if (forward) pk.at + 1 else pk.at - 1; + var arena = std.heap.ArenaAllocator.init(p.gpa); + defer arena.deinit(); + const row = rowAt(p, pk, arena.allocator(), pk.at) catch return true; + const at = switch (row.target) { + .place => |x| x, + else => return true, + }; + _ = wordOf(p, pk, &t.steps[i].list.text); + _ = Trail.replaceStep(p, id, at.path, at.at) catch |err| p.reportError(.at(id), "walk", err); + return true; +} + +/// Look on a list word in pane `id`'s trail (SPEC §6.3): the list unrolled +/// again in that pane's tag, its rows, marks, cursor and query as they were. +pub fn reopen(p: *Pardes, id: usize, index: u32) void { + const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept"); + const pane = p.panes[id] orelse return; + TagState.toRest(p); + pk.landing = pane.serial; + pk.made = false; + unroll(p, pk, pk.query.slice()); + unrollRows(p, pk); +} + +/// A list unrolled again: All's places found again, the cursor where it was. +fn unrollRows(p: *Pardes, pk: *Pick) void { + const at = pk.at; + if (!fuzzy(pk) and pk.source == .all) filter(p, pk); + p.view().tag_state.rows.at = @intCast(@min(at, std.math.maxInt(u16))); +} + +/// Exec on a list word (SPEC §6.3): its source run again with its query, +/// from pane `id`. +pub fn rerun(p: *Pardes, id: usize, index: u32) void { + const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept"); + var query: Kind.Buf(256) = .{}; + query.set(pk.query.slice()); + open(p, id, pk.source, pk.word.slice(), query.slice(), pk.rows); +} + +/// Resume (`SPC '`): the last picker reopened as it was, from pane `from`, +/// in the tag of the pane its Enter lands in. +pub fn resumeFrom(p: *Pardes, from: usize) void { + var newest: ?*Pick = null; + for (p.picks) |slot| if (slot) |pk| if (newest == null or pk.id > newest.?.id) { + newest = pk; + }; + const pk = newest orelse return p.setMessage(.at(from), "Resume: no picker yet"); + TagState.toRest(p); + if (p.panes[from] == null) return; + hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "Resume", err); + unroll(p, pk, pk.query.slice()); + unrollRows(p, pk); +} + /// B3 on a picker's row (mouse.zig bandPress): Enter on it. pub fn landHere(p: *Pardes) void { const pk = live(p) orelse return; @@ -1476,6 +1595,66 @@ test "M-l unrolls the act step, which says what it acts on; Copy puts the places try std.testing.expectEqual(@as(usize, 1), pk.queue.items.len); } +test "after Enter the list is a word in the reader's trail: n and N walk its rows in place, a Look on it reopens it with its cursor and marks, Exec runs it again, Resume reopens the last" { + 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\nthree\nfour\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); + _ = 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" }); + open(p, held, .list, "Refs", "", "alpha.zig:2:1 two\nbeta.zig:2:1 b2\nalpha.zig:4:1 four\n"); + const pk = live(p).?; + settle(p); + p.update(.{ .key = .{ .cp = Key.tab } }); + p.update(.{ .key = .{ .cp = Key.up } }); + p.update(.{ .key = .{ .cp = Key.enter } }); + // The reader: its owner, the list's word, the place. + const reader = Trail.readerOf(p, p.panes[held].?).?; + var t = &p.panes[reader].?.trail; + try std.testing.expectEqual(@as(u8, 3), t.n); + try std.testing.expect(t.steps[1] == .list); + try std.testing.expectEqualStrings("Refs 1/3 •1", t.steps[1].list.text.slice()); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), reader), "‹@p") != null); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), reader), " › Refs 1/3 •1 › ") != null); + // n: the next row, in place of the step (another file: a pane in its place). + p.view().active = reader; + p.update(.{ .key = .{ .cp = 'n', .text = "n" } }); + const r2 = Trail.readerOf(p, p.panes[held].?).?; + try std.testing.expectEqualStrings(b_path, p.panes[r2].?.file.?.path); + t = &p.panes[r2].?.trail; + try std.testing.expectEqual(@as(u8, 3), t.n); + try std.testing.expectEqualStrings("Refs 2/3 •1", t.steps[1].list.text.slice()); + p.update(.{ .key = .{ .cp = 'N', .text = "N", .shift = true } }); + const r3 = Trail.readerOf(p, p.panes[held].?).?; + try std.testing.expectEqualStrings(a_path, p.panes[r3].?.file.?.path); + try std.testing.expectEqual(@as(i32, 1), p.panes[r3].?.body.cur_row); + // Look on the word: the list again, in the reader's tag, as it was. + Trail.lookStep(p, r3, 1); + try std.testing.expect(live(p) == pk); + try std.testing.expectEqual(@as(?usize, r3), TagState.hostOf(p)); + try std.testing.expectEqual(@as(u16, 0), p.view().tag_state.rows.at); + try std.testing.expectEqual(@as(usize, 1), pk.marks.items.len); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Exec on it: a new picker of the same source. + Trail.execStep(p, r3, 1); + try std.testing.expect(live(p) != null and live(p) != pk); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Resume: the last one. + exec.runBuiltin(p, .Resume, held, "", null); + try std.testing.expect(live(p) != null); + 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/Trail.zig b/core/Trail.zig index 7166d810..b88215d9 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -162,6 +162,32 @@ pub fn go(p: *Pardes, id: usize, i: u8) !usize { return show(p, id, s.place.path.slice(), .{ .line = s.place.line, .col = s.place.col }); } +/// A list the pane's newest step came through (§6.2: a picker's Enter, +/// Pick.zig): its word before the step's place. +pub fn through(t: *Trail, s: Step) void { + if (t.cur >= t.n or t.steps[t.cur] != .place) return; + if (t.n == max_steps) { + const first: usize = @intFromBool(t.steps[0] == .owner); + if (t.cur <= first) return; + std.mem.copyForwards(Step, t.steps[first .. max_steps - 1], t.steps[first + 1 ..]); + t.n -= 1; + t.cur -= 1; + } + std.mem.copyBackwards(Step, t.steps[t.cur + 1 .. t.n + 1], t.steps[t.cur..t.n]); + t.steps[t.cur] = s; + t.n += 1; + t.cur += 1; +} + +/// Reading pane `id`'s current step replaced by `path` at `at`, no step +/// pushed (a list's `n`, §5.6); its slot after it, as `step`'s. +pub fn replaceStep(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize { + const to = placeOf(path, at.line, at.col) orelse return error.NameTooLong; + const t = &p.panes[id].?.trail; + if (t.cur < t.n) t.steps[t.cur] = to; + return show(p, id, path, at); +} + /// Pane `id` showing `path` at `at`, the keyboard on it: its caret moved /// in the file it shows, or a new pane on `path` in its place, its walk /// with it. A line past the new file's end is a miss that changes nothing. @@ -248,10 +274,11 @@ pub const Part = enum { back, forward }; fn wordOf(t: *const Trail, i: usize, buf: *[max_text + 16]u8) []const u8 { const s = t.steps[i]; if (s != .owner and i < t.cur and t.cur - i > shown_steps) return "·"; - return switch (s) { + // The step's own bytes, not a copy's (a copy is gone at the return). + return switch (t.steps[i]) { .owner => |serial| std.fmt.bufPrint(buf, "‹" ++ config.pane_addr ++ "{d}", .{serial}) catch unreachable, // a u32 fits .place => |at| std.fmt.bufPrint(buf, "{s}:{d}", .{ std.Io.Dir.path.basename(at.path.slice()), at.line }) catch unreachable, // a basename and a u32 fit - .list, .search, .recipe => |w| w.text.slice(), + .list, .search, .recipe => |*w| w.text.slice(), }; } @@ -302,8 +329,9 @@ pub fn stepAt(t: *const Trail, part: Part, off: usize) ?u8 { } /// Look on step `i` of pane `id`'s trail (§6.3): a place is gone back or -/// forward to, the owner focused; a list, a search or a recipe is the -/// pickers' and the prompts' to take (not yet: said). +/// forward to, the owner focused, a list unrolled again as it was +/// (Pick.reopen); a search or a recipe is the prompts' to take (not yet: +/// said). pub fn lookStep(p: *Pardes, id: usize, i: u8) void { const pane = p.panes[id] orelse return; switch (pane.trail.steps[i]) { @@ -311,7 +339,8 @@ pub fn lookStep(p: *Pardes, id: usize, i: u8) void { .owner => |serial| if (p.paneBySerial(serial)) |owner| { p.view().active = owner; } else p.reportFailure(id, "walk: its owner is closed"), - .list, .search, .recipe => p.setMessage(.at(id), "walk: a list, a search or a recipe is not walked yet"), + .list => |w| pardes.Pick.reopen(p, id, w.index), + .search, .recipe => p.setMessage(.at(id), "walk: a search or a recipe is not walked yet"), } } @@ -321,7 +350,8 @@ pub fn execStep(p: *Pardes, id: usize, i: u8) void { const pane = p.panes[id] orelse return; switch (pane.trail.steps[i]) { .place, .owner => lookStep(p, id, i), - .list, .search, .recipe => p.setMessage(.at(id), "walk: a list, a search or a recipe is not run again yet"), + .list => |w| pardes.Pick.rerun(p, id, w.index), + .search, .recipe => p.setMessage(.at(id), "walk: a search or a recipe is not run again yet"), } } diff --git a/core/builtins.zig b/core/builtins.zig index 12ab9da5..589915c2 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -1998,6 +1998,16 @@ 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 '`. +pub const Resume = struct { + pub fn run(c: Ctx) void { + pardes.Pick.resumeFrom(c.p, c.id); + } +}; + /// 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 6adebe1b..c924796a 100644 --- a/core/config.zig +++ b/core/config.zig @@ -145,6 +145,7 @@ pub const leader_path = paths: { .Back = "jo", .Forward = "ji", .Keep = "jk", + .Resume = "'", .Last = "jj", .Jumplist = "jl", .History = "fh", diff --git a/core/normal.zig b/core/normal.zig index 1f7ce1a7..2ec8a4da 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -1379,6 +1379,8 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! return look.lookWalk(p, if (a.role == .search_next) 1 else -1, false) else if (t.what == .body and pane.file != null and pane.places.answersN(p, pane)) return pane.places.step(p, pane, a.role == .search_next, a.count, t.select) + else if (t.what == .body and panes.Pick.walkList(p, v.active, a.role == .search_next)) + return else return searchStep(p.editor(), t, text, a.role == .search_next, a.count), .goto_word => return startJump(p, pane, t), diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index 4985fa42..43fdeb03 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -85,6 +85,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