summaryrefslogtreecommitdiff
path: root/core/Trail.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 21:10:15 -0300
committerGabriel Schneider <[email protected]>2026-11-24 21:10:17 -0300
commitb28053aede910b8714db4f27ef66e59dd96945c0 (patch)
treea0aea3ca051a21cf3378de5d587357e9208deebb /core/Trail.zig
parentabe3817e8dd0af41e6b5786bdbeb631219b58c23 (diff)
downloadpardes-b28053aede910b8714db4f27ef66e59dd96945c0.tar.gz
pardes-b28053aede910b8714db4f27ef66e59dd96945c0.zip
Prompt: `/` and `?` search a file's body as they are typed (walk UI, pick-ui SPEC.md §7.3, item 2 of line E): its places found from where it began (Places.search, the view's on the key, a frame's budget a tick after), tinted, the current one stronger and selected as soon as it is found (`?`: the last before the caret, once the text between is searched), the gutter marked in the blank after each line number (`▸` the current place's line, `▪` the others'), counted `3/7 · 5 lines` (`3/⋯` while they are found; the lines counted once, at the step they are all found, a pass to the last place), ` · wrapped` past the end from where it began, `0` for no match; a pattern that is no regex keeps the last places, dimmed (Places.paint), the reason in the count; Enter lands, the pattern in `/`, and folds the pane's one search word into its trail (`/dirty/ 3/7`, Trail.setWord: the newest back step, in place of the one it had); n and N write it again in place and echo `/dirty/ 4/7 · line 112` on the message row, ` ↻` after a step round an end, `–/7` with the selection off its places, every step (Prompt.settle beside the places'); the first Esc in normal mode clears a search's tints (SPEC §10.4's first step: C's Esc order when it lands) and the word stays, dimmed (draw.zig, Trail.spanOf); Look on the word lights its places again and selects the one it was on, Exec searches again from the caret (Trail.lookStep, execStep); `*` makes the selection's pattern the search word, no prompt and no query pane; Alt-Enter keeps the places as rows: today's query pane (Query.open .text), the body as it was; `?` is helix's backward search, a new role (modal.zig, config.zig); THE FAULTS THE TESTS MET, both B's and latent until a word step was made: Trail.wordOf returned the text of a COPY of the step (a slice of its stack frame: the word drawn as garbage), now the step's own bytes; Trail.lastCur held `cur` under `n`, though keep() leaves a held pane's at `n` (a search word alone: the dump's load moved it and the digests differed), now `n`; TEST FIRST: Prompt.zig "/ searches the body as it is typed ..." and "? searches back from the caret ..."; Places' `*` test reads the echo, Query's and Stream's `/` tests keep their query pane by Alt-Enter, Query's `*` test reads the word; test/perf.zig --search measures a key in `/` and `s` on a 1 MB file; goldens fsearch, lookrange (the prompt in the tag, the word in the trail); core-test 1016/1182 (166 skipped), shell-test 1229/1232, pane-test 182/184, behaviour-test 274/277 (the failures A's, as on item 1), process-test A's six and none of mine, term-test 17/17, kitty-test 45/45
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Trail.zig')
-rw-r--r--core/Trail.zig56
1 files changed, 47 insertions, 9 deletions
diff --git a/core/Trail.zig b/core/Trail.zig
index 7166d810..0ea893e2 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -38,8 +38,10 @@ cur: u8 = 0,
/// Kept, or edited since it was shown: it no longer walks (§6.5).
held: bool = false,
+/// `cur` is at most `n`: a held pane's (keep, a search's or a recipe's
+/// word alone) has no current place, past its steps.
pub fn lastCur(t: *const Trail) usize {
- return t.n -| 1;
+ return t.n;
}
/// One step of a walk, as its word says it (§2 "trail word").
@@ -194,6 +196,31 @@ fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
return free;
}
+/// `s`, a search's or a recipe's word, the pane's one of its kind (§7.3,
+/// §7.5): the one it had goes, and it is the newest back step.
+pub fn setWord(t: *Trail, s: Step) void {
+ var w: u8 = 0;
+ for (t.steps[0..t.n], 0..) |old, i| {
+ if (std.meta.activeTag(old) == std.meta.activeTag(s)) {
+ if (i < t.cur) t.cur -= 1;
+ continue;
+ }
+ t.steps[w] = old;
+ w += 1;
+ }
+ t.n = w;
+ if (t.n == max_steps) {
+ const first: usize = @intFromBool(t.steps[0] == .owner);
+ 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;
+}
+
/// Pane `id` held (§6.5): Keep, or an edit. It no longer walks, so the
/// walk leaves its trail (places, lists, its owner, forward steps); words
/// about its own text (a search, a recipe) stay. The next jump from its
@@ -246,12 +273,13 @@ pub const Part = enum { back, forward };
/// Step `i`'s word: `‹@p3`, `rank.zig:14`, a list's, search's or recipe's
/// own text; `·` when it is folded.
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) {
+ const s = &t.steps[i];
+ if (s.* != .owner and i < t.cur and t.cur - i > shown_steps) return "·";
+ // The step itself, not a copy: a word's text is the step's own bytes.
+ return switch (s.*) {
.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(),
};
}
@@ -285,6 +313,14 @@ pub fn bytes(t: *const Trail, part: Part) usize {
return n;
}
+/// Where back step `i`'s word is in what `write` writes for the back steps.
+pub fn spanOf(t: *const Trail, i: usize) [2]usize {
+ var buf: [max_text + 16]u8 = undefined;
+ var x: usize = 0;
+ for (0..i) |j| x += wordOf(t, j, &buf).len + sep.len;
+ return .{ x, x + wordOf(t, i, &buf).len };
+}
+
/// The step whose word in `part` is at byte `off` of what `write` wrote
/// for it, null on a separator or past them.
pub fn stepAt(t: *const Trail, part: Part, off: usize) ?u8 {
@@ -302,8 +338,8 @@ 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 search lit again (Prompt.zig); a list
+/// or a recipe is the pickers' and 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 +347,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"),
+ .search => pardes.Prompt.lookWord(p, id),
+ .list, .recipe => p.setMessage(.at(id), "walk: a list or a recipe is not walked yet"),
}
}
@@ -321,7 +358,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"),
+ .search => pardes.Prompt.execWord(p, id),
+ .list, .recipe => p.setMessage(.at(id), "walk: a list or a recipe is not run again yet"),
}
}