diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 20:39:07 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 20:42:02 -0300 |
| commit | 3621482c586b1d0d3601a1668a307918f1faea93 (patch) | |
| tree | 74900668c157fd681b4a510ff04ed9d4aa8b3eed /core/Trail.zig | |
| parent | 441e61294268bd0bb94abfa6b1ebb4ced23e726c (diff) | |
| download | pardes-3621482c586b1d0d3601a1668a307918f1faea93.tar.gz pardes-3621482c586b1d0d3601a1668a307918f1faea93.zip | |
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
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Trail.zig')
| -rw-r--r-- | core/Trail.zig | 42 |
1 files changed, 36 insertions, 6 deletions
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"), } } |
