summaryrefslogtreecommitdiff
path: root/core/Jump.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/Jump.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/Jump.zig')
-rw-r--r--core/Jump.zig95
1 files changed, 81 insertions, 14 deletions
diff --git a/core/Jump.zig b/core/Jump.zig
index 3d69d6c9..3632a039 100644
--- a/core/Jump.zig
+++ b/core/Jump.zig
@@ -274,11 +274,17 @@ pub fn trackJump(p: *Pardes) void {
/// always have, at the newest entry.
pub fn jumpBy(p: *Pardes, delta: i32) void {
const v = p.view();
- // A reading pane's walk first (pick-ui SPEC §6.4). Past its newest
+ // A pane's walk first (pick-ui SPEC §6.4, UX L'1). Past its newest
// step, Ctrl-i steps the Walk queue a picker left (Pick.stepQueue);
// then the jump list's.
if (pardes.Trail.walkBy(p, v.active, delta)) return;
if (delta > 0 and pardes.Pick.stepQueue(p, v.active)) return;
+ listBy(p, delta);
+}
+
+/// The jump list's step alone (`jumpBy`): past a walk's last word.
+pub fn listBy(p: *Pardes, delta: i32) void {
+ const v = p.view();
const older = delta < 0;
// At an end of the list: said, not a step that silently does nothing.
if (v.jumps.n == 0 or (older and v.jumps.cur == 0) or (!older and v.jumps.cur + 1 >= v.jumps.n))
@@ -338,7 +344,7 @@ pub fn jumpBy(p: *Pardes, delta: i32) void {
v.jumps.cur = @min(cur, w -| 1);
// The same step again, over the list without them: each
// round takes one file's entries away, so it ends.
- return jumpBy(p, delta);
+ return listBy(p, delta);
}
const e = found.?;
const from = v.active;
@@ -461,7 +467,7 @@ test "jump history terminal rectangle follows output and clears on reflow" {
try std.testing.expectEqual(.none, pane.sel[0].state);
}
-test "Ctrl-o at a walk's first place never rewrites its trail (UX L): after SPC f f words, Enter, /in_word, Enter, Ctrl-o goes to the first place, a second Ctrl-o leaves the list's and the search's words where they are, and Ctrl-i goes forward again" {
+test "Ctrl-o pops the walk one word at a time (UX L'1): after SPC f f words, Enter, /in_word, Enter, Ctrl-o puts the caret where the search started with its places lit, then reopens Find words as it was left, previewing here, then goes to the place before it; Ctrl-i comes back the same way; Esc leaves a reopened list as before the Ctrl-o; its Enter lands as its word's, the steps after it dropped" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 84, .rows = 20 });
defer p.deinit();
var tmp = std.testing.tmpDir(.{});
@@ -485,6 +491,12 @@ test "Ctrl-o at a walk's first place never rewrites its trail (UX L): after SPC
for (keys) |c| pp.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
}
}.f;
+ const echo = struct {
+ fn f(pp: *Pardes) []const u8 {
+ const said = pp.messages.headline() orelse return "";
+ return said.words();
+ }
+ }.f;
typeKeys(p, " ffwords");
var n: usize = 0;
while (n < 50 and (pardes.Pick.busy(p) or p.stream.busyFor(pardes.Pick.live(p).?.id))) : (n += 1) {
@@ -493,25 +505,80 @@ test "Ctrl-o at a walk's first place never rewrites its trail (UX L): after SPC
}
p.update(.{ .key = .{ .cp = pardes.Key.enter } });
p.sync();
+ try std.testing.expectEqualStrings("C-o back to Find words 1/1", echo(p));
typeKeys(p, "/in_word");
p.update(.{ .key = .{ .cp = pardes.Key.enter } });
p.sync();
+ try std.testing.expect(std.mem.startsWith(u8, echo(p), "C-o back to /in_word/ "));
+ {
+ // The search word holds where the search started: the landing.
+ const t = &p.panes[p.view().active].?.trail;
+ try std.testing.expect(t.n == 4 and t.cur == 3 and t.steps[2] == .search);
+ const from = t.steps[2].search.from;
+ try std.testing.expectEqualStrings("words.zig", std.Io.Dir.path.basename(from.path.slice()));
+ try std.testing.expect(from.line == 1 and from.col == 1);
+ }
const back: pardes.Key = .{ .cp = 'o', .ctrl = true };
const ahead: pardes.Key = .{ .cp = 'i', .ctrl = true };
- const Want = struct { file: []const u8, cur: u8 };
+ // After each key: the file the pane shows, where it is in its trail,
+ // the caret's line, Find words unrolled or not, the search lit or not.
+ const Want = struct { file: []const u8, cur: u8, line: i32, picker: bool, lit: bool };
+ const Check = struct {
+ fn f(pp: *Pardes, want: Want) !void {
+ const live = pardes.Pick.live(pp);
+ try std.testing.expectEqual(want.picker, live != null);
+ const id = if (live) |pk| pp.paneBySerial(pk.landing).? else pp.view().active;
+ const pane = pp.panes[id].?;
+ const t = &pane.trail;
+ if (live != null) try std.testing.expectEqualStrings("words", pp.view().tag_state.field.text()) else try std.testing.expectEqualStrings(want.file, std.Io.Dir.path.basename(pane.file.?.path));
+ if (live) |pk| try std.testing.expectEqual(pardes.Pick.Source.find, pk.source);
+ try std.testing.expectEqual(@as(u8, 4), t.n);
+ try std.testing.expectEqual(want.cur, t.cur);
+ try std.testing.expect(t.steps[0] == .place and t.steps[1] == .list and t.steps[2] == .search and t.steps[3] == .place);
+ try std.testing.expectEqual(@as(u32, 4), t.steps[3].place.line);
+ if (live == null) try std.testing.expectEqual(want.line, pane.body.cur_row + 1);
+ const set = &pane.places;
+ try std.testing.expectEqual(want.lit, live == null and set.shows(pane) and set.provenance == .search and std.mem.eql(u8, set.pattern, "in_word"));
+ }
+ };
for ([_]struct { key: pardes.Key, want: Want }{
- .{ .key = back, .want = .{ .file = "main.zig", .cur = 0 } },
- .{ .key = back, .want = .{ .file = "main.zig", .cur = 0 } },
- .{ .key = ahead, .want = .{ .file = "words.zig", .cur = 3 } },
- .{ .key = ahead, .want = .{ .file = "words.zig", .cur = 3 } },
+ .{ .key = back, .want = .{ .file = "words.zig", .cur = 2, .line = 1, .picker = false, .lit = true } },
+ .{ .key = back, .want = .{ .file = "words.zig", .cur = 2, .line = 1, .picker = true, .lit = false } },
+ .{ .key = back, .want = .{ .file = "main.zig", .cur = 0, .line = 1, .picker = false, .lit = false } },
+ .{ .key = ahead, .want = .{ .file = "main.zig", .cur = 0, .line = 1, .picker = true, .lit = false } },
+ .{ .key = ahead, .want = .{ .file = "words.zig", .cur = 2, .line = 1, .picker = false, .lit = true } },
+ .{ .key = ahead, .want = .{ .file = "words.zig", .cur = 3, .line = 4, .picker = false, .lit = true } },
}) |step| {
p.update(.{ .key = step.key });
p.sync();
- const pane = p.panes[p.view().active].?;
- const t = &pane.trail;
- try std.testing.expectEqualStrings(step.want.file, std.Io.Dir.path.basename(pane.file.?.path));
- try std.testing.expectEqual(@as(u8, 4), t.n);
- try std.testing.expectEqual(step.want.cur, t.cur);
- try std.testing.expect(t.steps[1] == .list and t.steps[2] == .search);
+ try Check.f(p, step.want);
}
+ // Esc from a list a walk reopened: rest exactly as before the Ctrl-o.
+ p.update(.{ .key = back });
+ p.update(.{ .key = back });
+ try Check.f(p, .{ .file = "words.zig", .cur = 2, .line = 1, .picker = true, .lit = false });
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ p.sync();
+ try Check.f(p, .{ .file = "words.zig", .cur = 2, .line = 1, .picker = false, .lit = true });
+ // Its Enter lands as its word's: a step from it, the search's word and
+ // the place after it dropped.
+ p.update(.{ .key = back });
+ try std.testing.expect(pardes.Pick.live(p) != null);
+ p.update(.{ .key = .{ .cp = pardes.Key.enter } });
+ p.sync();
+ var t = &p.panes[p.view().active].?.trail;
+ try std.testing.expectEqual(@as(u8, 3), t.n);
+ try std.testing.expectEqual(@as(u8, 2), t.cur);
+ try std.testing.expect(t.steps[0] == .place and t.steps[1] == .list and t.steps[2] == .place);
+ try std.testing.expectEqualStrings("Find words 1/1", t.steps[1].list.text.slice());
+ try std.testing.expectEqualStrings("words.zig", std.Io.Dir.path.basename(p.panes[p.view().active].?.file.?.path));
+ // Backspace on its empty field walks on, as Ctrl-o.
+ p.update(.{ .key = back });
+ try std.testing.expect(pardes.Pick.live(p) != null);
+ for (0.."words".len + 1) |_| p.update(.{ .key = .{ .cp = pardes.Key.backspace } });
+ p.sync();
+ try std.testing.expect(pardes.Pick.live(p) == null);
+ t = &p.panes[p.view().active].?.trail;
+ try std.testing.expectEqualStrings("main.zig", std.Io.Dir.path.basename(p.panes[p.view().active].?.file.?.path));
+ try std.testing.expect(t.n == 3 and t.cur == 0);
}