diff options
Diffstat (limited to 'core/Jump.zig')
| -rw-r--r-- | core/Jump.zig | 95 |
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); } |
