summaryrefslogtreecommitdiff
path: root/core/Prompt.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 00:04:32 -0300
committerGabriel Schneider <[email protected]>2026-11-26 02:11:20 -0300
commit3ace8b385e02a54830decb6aa48d1fa28d076a18 (patch)
tree0134d81f9fee3ca31f8037d0e894388abd30fffe /core/Prompt.zig
parent94f00e966c908d370e34ed5e0496a86b33de26d6 (diff)
downloadpardes-3ace8b385e02a54830decb6aa48d1fa28d076a18.tar.gz
pardes-3ace8b385e02a54830decb6aa48d1fa28d076a18.zip
Trail, Pick, Prompt, Jump: Ctrl-o pops the walk one word at a time (UX DESIGN L'1, binding; the user: "I did spc f f then did /something but I didn't know how to get back to the previous one", "the pickers are kinda shown as a stack right? I felt like I could pop the current one"): the trail's words, left to right, are the stack, and Ctrl-o steps one word left of where the pane is, Ctrl-i one right; onto a place as before (Trail.go); onto a list's word, that kept picker unrolls again in this pane's tag as it was left (query, cursor, marks), previewing here (Pick.reopen with `walking`, its step): Esc gives rest exactly as before the Ctrl-o, Enter lands as that word's (a step from it, the steps after it dropped, its word saying where it is now), Ctrl-o, Ctrl-i and Backspace on its empty field (after its refinements) roll it up unlanded and walk on (Pick.walkOn; past the last word the jump list's step alone, Jump.listBy); Ctrl-i in it is Tab, a mark, where the terminal cannot tell them apart; onto a search's word, the caret back where the search started and its places lit (Prompt.light, Look's without the select): `Step.search` is a `Search` that holds its start, path, line and column, recorded as `/` commits (Prompt.word from Places.origin) and by `*`; the pane is then at that word (`cur` on it: Trail.backs writes it before the path, n and N walk it, keep keeps it, a step from it keeps it, go and replaceStep never write a place over it); a held pane walks its own words, a search's and a recipe's; a list no longer kept is said (`walk: that list is gone: the last 8 are kept`) and passed by; the owner is no word to walk; Jumps new-pane walks nothing, as before; D8's fold takes places only: each run of places older than the newest `whole` back steps (or past the first two forward) is one `+N` where it starts, a list's word folds only where the tag keeps its newest step alone and never the newest list's, a search's or a recipe's never (Trail.folds; draw.zig dims every run's `+N`); after a landing (Pick.listed) and a search's Enter (Prompt.land) the notice row says, as an echo never logged, what the next Ctrl-o reaches, `C-o back to Find words 1/1` (Trail.sayBack); THE CAUSE of the user's trouble (UX L1): Trail.walkBy skipped every word but a place (`if (t.steps[i] != .place) continue;`), so Ctrl-o after the search went to main.zig:1, past both the search and the list, and nothing said which key would pop; RUN (TEST FIRST): Jump.zig "Ctrl-o pops the walk one word at a time (UX L'1) ..." (W2's test extended) types the user's keys in an 84x20 session of main.zig (SPC f f words, Enter, /in_word, Enter, then Ctrl-o x3 and Ctrl-i x3) and asks after each key the file, the trail's four steps and where the pane is among them, the caret's line, Find words unrolled or not and the search lit or not, then Esc from a reopened list (as before the Ctrl-o), its Enter (the search's word and the place after it dropped, `Find words 1/1` kept) and Backspace on its empty field (walks on to main.zig): fails on the base at Jump.zig:565 on the first Ctrl-o (expected words.zig, found main.zig), passes now; Trail.zig "the fold takes places alone (UX L'1) ..." (runs of places each a `+N`, a click on each its newest, two lists with the newest step alone, a search's word never) and "a held pane walks its own words (UX L'1) ..." (Ctrl-o puts the caret at 20:3 where `/line 9` began, its places lit; past it the jump list's); the notice-row test of walk UI G 2e now reads the echo, then the caret's place once it is retired; a user hit it on every Ctrl-o after a picker's Enter or a search; goldens re-recorded: find and fsearch (the notice row after a picker's Enter and a search's Enter reads the echo); ttyhelp is the merge's placeholder (M1 re-records it); the perf cell walk-pop (test/perf.zig, run only when named: Ctrl-o onto a list word reopening it in the key's own frame, then Esc), 326 us a pair on small in ReleaseFast; core-test 1124/1298 (173 skipped; the G 2e notice-row test, failing on the echo, updated and passing alone), shell-test 1346/1349 (3 skipped), behaviour-test 280/280, pane-test 183/184, process-test 3 of 147 failed before the two goldens moved (find, fsearch: the echo; ttyhelp the placeholder); load 2.2 to 7.2
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Prompt.zig')
-rw-r--r--core/Prompt.zig47
1 files changed, 34 insertions, 13 deletions
diff --git a/core/Prompt.zig b/core/Prompt.zig
index c54bb228..afe9f78e 100644
--- a/core/Prompt.zig
+++ b/core/Prompt.zig
@@ -445,8 +445,10 @@ fn land(p: *Pardes, id: usize, pane: *Pane, op: Op, pat: []const u8, bad: bool)
p.registers.put(p.gpa, '/', pat, 0, 1, true) catch |err| return p.reportError(.at(id), "search", err);
p.registers.last_search = '/';
set.provenance = .search;
+ const from = set.origin(pane);
set.forget(p.gpa);
- word(pane, if (op == .search_back) '?' else '/', pat);
+ word(p, pane, if (op == .search_back) '?' else '/', pat, from);
+ Trail.sayBack(p, id);
}
/// Alt-Enter in `/ ?` or `s S K A-K` (SPEC §7.2): the result kept as a
@@ -688,36 +690,44 @@ pub fn execRecipe(p: *Pardes, id: usize) void {
/// Pane `pane`'s search word, `/re/ 3/7`: one a pane, its `index` the
/// length of its `/re/` with bit 16 set after n or N went round an end.
-fn wordOf(pane: *Pane) ?*Trail.Word {
+fn wordOf(pane: *Pane) ?*Trail.Search {
for (pane.trail.steps[0..pane.trail.n]) |*step| if (step.* == .search) return &step.search;
return null;
}
-fn patternOf(w: *const Trail.Word) []const u8 {
+fn patternOf(w: *const Trail.Search) []const u8 {
const end = patternEnd(w);
return if (end < 2) "" else w.text.slice()[1 .. end - 1];
}
/// Where a search word's `/re/` ends: held to its text (a damaged image's
/// says anything).
-fn patternEnd(w: *const Trail.Word) u16 {
+fn patternEnd(w: *const Trail.Search) u16 {
return std.math.clamp(@as(u16, @truncate(w.index)), @min(2, w.text.len), w.text.len);
}
/// Whether the places the pane's body shows are its search word's.
-fn lights(pane: *const Pane, w: *const Trail.Word) bool {
+fn lights(pane: *const Pane, w: *const Trail.Search) bool {
const set = &pane.places;
return set.shows(pane) and set.provenance == .search and !set.literal and std.mem.eql(u8, set.pattern, patternOf(w));
}
/// `pat`, delimited by `delim`, as pane `pane`'s one search word, in place
-/// of the one it had, written for where its places stand.
-fn word(pane: *Pane, delim: u8, pat: []const u8) void {
+/// of the one it had, written for where its places stand, its start the
+/// byte `from` of its text (UX L'1: a walk back onto it puts the caret
+/// there).
+fn word(p: *Pardes, pane: *Pane, delim: u8, pat: []const u8, from: usize) void {
// Its pattern and its place in the trail's room, else none.
if (pat.len + 2 + 32 > Trail.max_text) return;
- var w: Trail.Word = .{};
+ const f = &pane.file.?;
+ var w: Trail.Search = .{};
_ = w.text.print("{c}{s}{c}", .{ delim, pat, delim });
w.index = w.text.len;
+ if (f.path.len <= Trail.max_text) if (File.lineIndex(p.gpa, f)) |index| {
+ const line = Places.lineOf(index, @min(from, f.content.len));
+ w.from = .{ .line = @intCast(line + 1), .col = @intCast(@min(from, f.content.len) - File.lineStart(p.gpa, f, line) + 1) };
+ w.from.path.set(f.path);
+ } else |_| {};
pane.trail.setWord(.{ .search = w });
refresh(pane, false);
}
@@ -796,8 +806,9 @@ pub fn stepped(p: *Pardes, id: usize, forward: bool, before: ?usize) void {
/// `*`: pattern `pat`, the selection's (in `/` already), lights its places
/// in `pane`'s body and is its search word, no prompt asked (SPEC §7.3).
pub fn star(p: *Pardes, pane: *Pane, pat: []const u8) void {
+ const sel = pane.body.primaryRange(pane.file.?.content, 0);
pane.places.search(p, pane, .search, 0, pat, false, null, false);
- word(pane, '/', pat);
+ word(p, pane, '/', pat, @min(sel.anchor, sel.head));
}
/// Look on pane `id`'s search word (SPEC §6.3): its places lit again and
@@ -806,15 +817,25 @@ pub fn lookWord(p: *Pardes, id: usize) void {
const pane = p.panes[id] orelse return;
const w = wordOf(pane) orelse return;
const set = &pane.places;
+ light(p, id);
+ const rest = w.text.slice()[patternEnd(w)..];
+ const n = std.fmt.parseInt(usize, std.mem.trim(u8, rest[0 .. std.mem.indexOfScalar(u8, rest, '/') orelse rest.len], " "), 10) catch return;
+ if (n > 0 and n <= set.hits.items.len) set.goTo(p.settings.tab, pane, n - 1, false);
+}
+
+/// Pane `id`'s search word's places lit again, `/` its pattern, the caret
+/// where it is: a Look on the word, a walk onto it (Trail.walkFrom, the
+/// caret where the search started, UX L'1).
+pub fn light(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ const w = wordOf(pane) orelse return;
+ const set = &pane.places;
const pat = patternOf(w);
p.registers.put(p.gpa, '/', pat, 0, 1, true) catch |err| return p.reportError(.at(id), "search", err);
p.registers.last_search = '/';
set.search(p, pane, .search, 0, pat, false, null, false);
set.fill(p, pane, std.math.maxInt(usize), regexp.Regex.budget);
p.view().active = id;
- const rest = w.text.slice()[patternEnd(w)..];
- const n = std.fmt.parseInt(usize, std.mem.trim(u8, rest[0 .. std.mem.indexOfScalar(u8, rest, '/') orelse rest.len], " "), 10) catch return;
- if (n > 0 and n <= set.hits.items.len) set.goTo(p.settings.tab, pane, n - 1, false);
}
/// Exec on it: searched again from the caret, as its prompt and Enter
@@ -841,7 +862,7 @@ pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize {
if (Trail.outOfRest(p, pane)) return null;
const t = &pane.trail;
const whole = pardes.tagline.folded(p, pane).whole;
- for (t.steps[0..t.cur], 0..) |*step, i| if (step.* == .search) {
+ for (t.steps[0..t.backs()], 0..) |*step, i| if (step.* == .search) {
if (lights(pane, &step.search) or t.isFolded(i, whole)) return null;
return t.spanOf(i, whole);
};