summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Jump.zig95
-rw-r--r--core/Pick.zig59
-rw-r--r--core/Prompt.zig47
-rw-r--r--core/Trail.zig295
-rw-r--r--core/draw.zig8
-rw-r--r--test/perf.zig28
-rw-r--r--test/snapshots/find.golden2
-rw-r--r--test/snapshots/fsearch.golden2
8 files changed, 439 insertions, 97 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);
}
diff --git a/core/Pick.zig b/core/Pick.zig
index 8669314f..c49e8682 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -147,6 +147,10 @@ act_at: u8 = 0,
queue: std.ArrayList(Queued) = .empty,
queue_bytes: std.ArrayList(u8) = .empty,
queue_at: u32 = 0,
+/// The step of its landing pane's trail a walk reopened it at (Ctrl-o,
+/// UX L'1): its Ctrl-o and Ctrl-i walk on from that word, and its Enter
+/// lands as that word's, the steps after it dropped.
+walking: ?u8 = null,
pub const Queued = struct { path: u32, len: u16, line: u32, col: u32 };
@@ -957,6 +961,7 @@ pub fn rollUp(p: *Pardes) void {
pk.spine = .rows;
pk.at = s.rows.at;
pk.unrolled = false;
+ pk.walking = null;
if (p.stream.target == pk.id) _ = p.stream.stop();
restore(p, pk);
}
@@ -1148,6 +1153,10 @@ pub fn key(p: *Pardes, k: Key) void {
_ = s.field.key(k);
return;
}
+ // A list a walk reopened (UX L'1): Ctrl-o and Ctrl-i walk on from its
+ // word, the list rolled up unlanded. Ctrl-i is Tab where the terminal
+ // cannot tell them apart: a mark, as Tab.
+ if (pk.walking) |at| if (ctrl and (k.cp == 'o' or k.cp == 'i')) return walkOn(p, pk, at, if (k.cp == 'o') -1 else 1);
if (alt and (k.cp == Key.enter or k.cp == 'l')) {
pk.spine = .acts;
pk.act_at = 0;
@@ -1308,6 +1317,7 @@ fn back(p: *Pardes, pk: *Pick) void {
if (!fuzzy(pk) and pk.source == .all) filter(p, pk);
return;
}
+ if (pk.walking) |at| return walkOn(p, pk, at, -1);
const keys = pk.keys;
TagState.toRest(p);
if (keys.len == 0) return;
@@ -1318,6 +1328,16 @@ fn back(p: *Pardes, pk: *Pick) void {
s.unrolled = true;
}
+/// Ctrl-o (`delta` < 0) or Ctrl-i in a list a walk reopened at step `at`
+/// of its landing pane's trail (UX L'1): the list rolled up unlanded, the
+/// pane as it was, and the walk on from the list's word; past the last
+/// word, the jump list's step.
+fn walkOn(p: *Pardes, pk: *Pick, at: u8, delta: i32) void {
+ const id = p.paneBySerial(pk.landing) orelse return TagState.toRest(p);
+ TagState.toRest(p);
+ if (!Trail.walkFrom(p, id, at, delta)) pardes.Jump.listBy(p, delta);
+}
+
/// C-q: the rows (the marked, else all, `Query.max_rows` at most) kept as
/// text in a +Search under the asking pane, the source's word and query
/// its first line, each row an address a Look opens.
@@ -1379,6 +1399,7 @@ fn land(p: *Pardes, wanted: How) void {
const a = arena.allocator();
const picked = pickedRows(p, pk, a) catch return;
if (picked.len == 0) return;
+ const walking = pk.walking;
// Walk: the first now, the others queued for C-i.
pk.queue.clearRetainingCapacity();
pk.queue_bytes.clearRetainingCapacity();
@@ -1412,9 +1433,17 @@ fn land(p: *Pardes, wanted: How) void {
_ = p.store.reopen(p, serial, from);
},
.place => |at| if (k == 0 and (how == .walk or how == .queue)) {
+ // A list a walk reopened lands as its word's (UX L'1): a step
+ // from that word, the steps after it dropped.
+ const word: ?u8 = if (walking) |i| (if (from == landing and isWord(p.panes[from].?, i, pk.id)) i else null) else null;
+ if (word) |i| {
+ const trail = &p.panes[from].?.trail;
+ trail.n = i + 1;
+ trail.cur = i;
+ }
switch (look.open(p, from, at.path, at.at, .replace)) {
.none => {},
- else => listed(p, pk),
+ else => listed(p, pk, word),
}
} else if (k == 0 and how == .column) {
// A column made only where there is no free space (UX J1).
@@ -1452,11 +1481,25 @@ fn wordOf(p: *const Pardes, pk: *const Pick, buf: *Kind.Buf(Trail.max_text)) []c
return buf.slice();
}
+/// Whether step `i` of pane `pane`'s trail is picker `id`'s word.
+fn isWord(pane: *const Pane, i: u8, id: u32) bool {
+ const t = &pane.trail;
+ return i < t.n and t.steps[i] == .list and t.steps[i].list.index == id;
+}
+
/// The list rolled into the trail of the reading pane it landed in, its
-/// word before the place: the list `n` and `N` walk there.
-fn listed(p: *Pardes, pk: *const Pick) void {
- const pane = p.panes[p.view().active] orelse return;
+/// word before the place: the list `n` and `N` walk there; a list a walk
+/// reopened at step `at` says where it is now in that word. The notice row
+/// says what Ctrl-o goes back to (UX L'1).
+fn listed(p: *Pardes, pk: *const Pick, at: ?u8) void {
+ const id = p.view().active;
+ const pane = p.panes[id] orelse return;
if (!Trail.reading(p, pane)) return;
+ defer Trail.sayBack(p, id);
+ if (at) |i| if (isWord(pane, i, pk.id)) {
+ _ = wordOf(p, pk, &pane.trail.steps[i].list.text);
+ return;
+ };
var w: Trail.Word = .{ .index = pk.id };
_ = wordOf(p, pk, &w.text);
Trail.through(&pane.trail, .{ .list = w });
@@ -1502,9 +1545,10 @@ pub fn walkList(p: *Pardes, id: usize, forward: bool) bool {
return true;
}
-/// Look on a list word in pane `id`'s trail (SPEC §6.3): the list unrolled
-/// again in that pane's tag, its rows, marks, cursor and query as they were.
-pub fn reopen(p: *Pardes, id: usize, index: u32) void {
+/// Look on a list word in pane `id`'s trail (SPEC §6.3), or a walk onto
+/// it at step `walking` (UX L'1): the list unrolled again in that pane's
+/// tag, its rows, marks, cursor and query as they were.
+pub fn reopen(p: *Pardes, id: usize, index: u32, walking: ?u8) void {
const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept");
const pane = p.panes[id] orelse return;
TagState.toRest(p);
@@ -1512,6 +1556,7 @@ pub fn reopen(p: *Pardes, id: usize, index: u32) void {
pk.made = false;
unroll(p, pk, pk.query.slice());
unrollRows(p, pk);
+ pk.walking = walking;
}
/// A list unrolled again: All's places found again, the cursor where it was.
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);
};
diff --git a/core/Trail.zig b/core/Trail.zig
index 2a37d68a..cd8eb924 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -57,15 +57,17 @@ pub const Step = union(enum) {
/// A list the pane came through (`Find pick 3/6 •2`, §5.6): its word
/// and the pickers' index for it. Made as a picker lands (Pick.listed).
list: Word,
- /// A search made in the pane (`/dirty/ 3/7`, §7.3). Made by a search
- /// prompt (Prompt.word).
- search: Word,
+ /// A search made in the pane (`/dirty/ 3/7`, §7.3) and where it
+ /// started: a walk back onto it puts the caret there (UX L'1). Made by
+ /// a search prompt (Prompt.word).
+ search: Search,
/// A chain of selection prompts as an Edit line (§7.5). Made by the sam
/// prompts (Prompt.link).
recipe: Word,
};
pub const Place = struct { path: Kind.Buf(max_text) = .{}, line: u32 = 0, col: u32 = 0 };
pub const Word = struct { text: Kind.Buf(max_text) = .{}, index: u32 = 0 };
+pub const Search = struct { text: Kind.Buf(max_text) = .{}, index: u32 = 0, from: Place = .{} };
/// A file the walk can show: a text on its path, not an output, a
/// listing, a pager, a query or a kind (§2: what is not a file is held).
@@ -157,8 +159,11 @@ fn push(t: *Trail, s: Step) void {
pub fn step(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
const pane = p.panes[id].?;
const t = &pane.trail;
+ // At a word (a walk onto a search's, a list's Enter, UX L'1): a step
+ // from it keeps the word, and is one wherever the pane is.
+ const word = t.cur < t.n and t.steps[t.cur] != .place;
// Where it is already: no step.
- if (here(pane)) |was| if (samePlace(was, path, at.line)) return show(p, id, path, at);
+ if (!word) if (here(pane)) |was| if (samePlace(was, path, at.line)) return show(p, id, path, at);
for (t.steps[0..t.cur], 0..) |s, i| if (samePlace(s, path, at.line)) return go(p, id, @intCast(i));
if (t.n > t.cur + 1) for (t.steps[t.cur + 1 .. t.n], t.cur + 1..) |s, j| if (samePlace(s, path, at.line)) return go(p, id, @intCast(j));
const to = placeOf(path, at.line, at.col) orelse return error.NameTooLong;
@@ -166,7 +171,7 @@ pub fn step(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
if (here(pane)) |was| {
if (t.n > t.cur) {
t.n = t.cur + 1;
- t.steps[t.cur] = was;
+ if (!word) t.steps[t.cur] = was;
} else push(t, was);
} else t.n = t.cur;
push(t, to);
@@ -175,19 +180,27 @@ pub fn step(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
}
/// Go to step `i` of reading pane `id`'s trail, back or forward (§6.4):
-/// where it is now becomes the step it leaves, the ones between stay.
+/// where it is now becomes the step it leaves (a word it is at stays the
+/// word), the ones between stay.
pub fn go(p: *Pardes, id: usize, i: u8) !usize {
const pane = p.panes[id].?;
const t = &pane.trail;
if (i >= t.n or t.steps[i] != .place) return id;
const s = t.steps[i];
- if (t.n > t.cur) if (here(pane)) |was| {
- t.steps[t.cur] = was;
- };
+ leave(pane);
t.cur = i;
return show(p, id, s.place.path.slice(), .{ .line = s.place.line, .col = s.place.col });
}
+/// Where pane `pane` is now kept as the step it leaves, when that is a
+/// place: a word it is at stays the word.
+fn leave(pane: *Pane) void {
+ const t = &pane.trail;
+ if (t.cur < t.n and t.steps[t.cur] == .place) if (here(pane)) |was| {
+ t.steps[t.cur] = was;
+ };
+}
+
/// 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 {
@@ -210,7 +223,7 @@ pub fn through(t: *Trail, s: Step) void {
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;
+ if (t.cur < t.n and t.steps[t.cur] == .place) t.steps[t.cur] = to;
return show(p, id, path, at);
}
@@ -327,7 +340,7 @@ pub fn keep(pane: *Pane) void {
if (t.held) return;
t.held = true;
var w: u8 = 0;
- for (t.steps[0..t.cur]) |s| if (s == .search or s == .recipe) {
+ for (t.steps[0..t.backs()]) |s| if (s == .search or s == .recipe) {
t.steps[w] = s;
w += 1;
};
@@ -350,23 +363,96 @@ pub fn edited(p: *Pardes, f: *const panes.File.State) void {
}
-/// Back (`delta` < 0) or forward one place in reading pane `id`'s walk,
-/// as Ctrl-o and Ctrl-i go first (pick-ui SPEC §6.4): true when it had
-/// one that way, false to leave the step to the jump list (Jump.jumpBy).
+/// Back (`delta` < 0) or forward one word in pane `id`'s walk, as Ctrl-o
+/// and Ctrl-i go first (pick-ui SPEC §6.4, UX L'1): true when it had one
+/// that way, false to leave the step to the jump list (Jump.jumpBy).
pub fn walkBy(p: *Pardes, id: usize, delta: i32) bool {
const pane = p.panes[id] orelse return false;
- if (!reading(p, pane)) return false;
+ return walkFrom(p, id, pane.trail.cur, delta);
+}
+
+/// One word `delta`'s way from step `from` of pane `id`'s walk (UX L'1:
+/// the trail's words are the stack): onto a place, there (`go`); onto a
+/// list's word, that list unrolled again as it was left, previewing here,
+/// its Ctrl-o and Ctrl-i going on from its word (Pick.reopen); onto a
+/// search's, the caret where the search started and its places lit
+/// (Prompt.light); a held pane onto its own words, a search's and a
+/// recipe's (its selections back). A list no longer kept is said and
+/// passed by.
+pub fn walkFrom(p: *Pardes, id: usize, from: usize, delta: i32) bool {
+ const pane = p.panes[id] orelse return false;
const t = &pane.trail;
- var i: usize = t.cur;
- while (if (delta < 0) i > 0 else i + 1 < t.n) {
- i = if (delta < 0) i - 1 else i + 1;
- if (t.steps[i] != .place) continue;
- _ = go(p, id, @intCast(i)) catch |err| p.reportError(.at(id), "walk", err);
+ var at = from;
+ while (reach(p, pane, at, delta)) |i| {
+ switch (t.steps[i]) {
+ .owner => return false, // reach passes it by
+ .place => _ = go(p, id, i) catch |err| p.reportError(.at(id), "walk", err),
+ .list => |w| {
+ if (pardes.Pick.byId(p, w.index) == null) {
+ p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept");
+ at = i;
+ continue;
+ }
+ pardes.Pick.reopen(p, id, w.index, i);
+ },
+ .search => |*s| {
+ leave(pane);
+ t.cur = i;
+ // Its place copied: a step to another file frees this pane.
+ const start = s.from;
+ var to = id;
+ if (start.path.len > 0 and !t.held) {
+ to = show(p, id, start.path.slice(), .{ .line = start.line, .col = start.col }) catch |err| {
+ p.reportError(.at(id), "walk", err);
+ return true;
+ };
+ } else if (start.path.len > 0 and std.mem.eql(u8, start.path.slice(), pane.file.?.path)) {
+ look.focusPaneLine(p, id, .{ .line = start.line, .col = start.col }, .center);
+ }
+ pardes.Prompt.light(p, to);
+ },
+ .recipe => {
+ t.cur = i;
+ pardes.Prompt.lookRecipe(p, id);
+ },
+ }
return true;
}
return false;
}
+/// The step a walk from step `from` of pane `pane`'s trail reaches
+/// `delta`'s way (UX L'1): a place, a list's word or a search's of a
+/// reading pane; a held pane's own words, a search's and a recipe's; never
+/// the owner. Only where it walks: a file, in a session whose jumps walk.
+fn reach(p: *const Pardes, pane: *const Pane, from: usize, delta: i32) ?u8 {
+ if (p.settings.jumps != .walk or !isFile(pane)) return null;
+ const t = &pane.trail;
+ var i = from;
+ while (if (delta < 0) i > 0 else i + 1 < t.n) {
+ i = if (delta < 0) i - 1 else i + 1;
+ switch (t.steps[i]) {
+ .owner => {},
+ .search => return @intCast(i),
+ .place, .list => if (!t.held) return @intCast(i),
+ .recipe => if (t.held) return @intCast(i),
+ }
+ }
+ return null;
+}
+
+/// After a landing and a search's Enter in pane `id` (UX L'1): the word
+/// its next Ctrl-o reaches, said on the notice row as an echo, `C-o back
+/// to Find words 1/1`, never logged.
+pub fn sayBack(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ const i = reach(p, pane, pane.trail.cur, -1) orelse return;
+ var buf: [max_text + 16]u8 = undefined;
+ var said: [max_text + 32]u8 = undefined;
+ const text = std.fmt.bufPrint(&said, "C-o back to {s}", .{wordOf(&pane.trail, i, &buf)}) catch return;
+ _ = pardes.Messages.keep(p, .echo, pane.serial, "", text);
+}
+
// ---- the words ----
/// `newest`: out of rest (UX D1), the owner's word and the newest back
@@ -387,7 +473,8 @@ fn wordOf(t: *const Trail, i: usize, buf: *[max_text + 16]u8) []const u8 {
while (from > 0 and shared(t, i, path[from..])) from = if (std.mem.lastIndexOfScalar(u8, path[0 .. from - 1], '/')) |slash| slash + 1 else 0;
break :place std.fmt.bufPrint(buf, "{s}:{d}", .{ path[from..], at.line }) catch unreachable; // a path and a u32 fit
},
- .list, .search, .recipe => |*w| w.text.slice(),
+ .list, .recipe => |*w| w.text.slice(),
+ .search => |*s| s.text.slice(),
};
}
@@ -406,10 +493,17 @@ fn shared(t: *const Trail, i: usize, end: []const u8) bool {
const sep = " › ";
+/// The end of the steps written before the path: the back steps, and the
+/// word the pane is at when a walk stepped onto one (UX L'1: a search's,
+/// its caret where the search started).
+pub fn backs(t: *const Trail) usize {
+ return if (t.cur < t.n and t.steps[t.cur] != .place) t.cur + 1 else t.cur;
+}
+
/// The steps a part writes.
fn range(t: *const Trail, part: Part) [2]usize {
return switch (part) {
- .back, .newest => .{ 0, t.cur },
+ .back, .newest => .{ 0, t.backs() },
.forward => .{ @min(t.n, t.cur + 1), t.n },
};
}
@@ -417,20 +511,34 @@ fn range(t: *const Trail, part: Part) [2]usize {
/// The forward steps written whole after the path at rest; the rest fold.
pub const shown_ahead = 2;
-/// Steps [lo, hi) of `part` folded into one dim `+N` word where the first
-/// of them is (UX D8): at rest the back steps older than the newest
-/// `whole` (never the owner), the forward steps past `shown_ahead`.
-fn foldOf(t: *const Trail, part: Part, whole: usize) [2]usize {
+/// Whether step `i` folds into a dim `+N` in `part`, one `+N` a run of them
+/// where its first is (UX D8, L'1: the fold takes places): at rest a place
+/// older than the newest `whole` back steps, or past the first
+/// `shown_ahead` forward steps; a list's word only where the tag keeps its
+/// newest step alone (`whole` 1), and never the newest list's; the owner's,
+/// a search's and a recipe's never.
+fn folds(t: *const Trail, part: Part, whole: usize, i: usize) bool {
+ const end = t.backs();
return switch (part) {
- .back => back: {
- const lo: usize = @intFromBool(t.cur > 0 and t.steps[0] == .owner);
- break :back .{ lo, @max(lo, t.cur -| whole) };
+ .newest => false,
+ .forward => t.steps[i] == .place and i > t.cur + shown_ahead,
+ .back => i + whole < end and switch (t.steps[i]) {
+ .place => true,
+ .list => whole == 1 and for (t.steps[i + 1 .. end]) |s| {
+ if (s == .list) break true;
+ } else false,
+ .owner, .search, .recipe => false,
},
- .forward => .{ @min(t.n, t.cur + 1 + shown_ahead), t.n },
- .newest => .{ 0, 0 },
};
}
+/// The first of step `i`'s run of folded steps in `part`.
+fn runStart(t: *const Trail, part: Part, whole: usize, i: usize) usize {
+ var at = i;
+ while (at > range(t, part)[0] and folds(t, part, whole, at - 1)) at -= 1;
+ return at;
+}
+
/// The cells of the newest step's word out of rest: a longer one is cut
/// in its middle (UX D1: `Find pick…3/6`).
const newest_cells = 24;
@@ -440,9 +548,13 @@ const newest_cells = 24;
/// of rest the owner's and the newest step's alone, a word longer than
/// `newest_cells` keeping its first and last cells around a `…`.
fn wordIn(t: *const Trail, part: Part, whole: usize, i: usize, buf: *[max_text + 16]u8, cut: *[max_text + 16]u8) ?[]const u8 {
- if (part == .newest and t.steps[i] != .owner and i + 1 != t.cur) return null;
- const fold = foldOf(t, part, whole);
- if (i >= fold[0] and i < fold[1]) return if (i == fold[0]) std.fmt.bufPrint(buf, "+{d}", .{fold[1] - fold[0]}) catch unreachable else null;
+ if (part == .newest and t.steps[i] != .owner and i + 1 != t.backs()) return null;
+ if (folds(t, part, whole, i)) {
+ if (runStart(t, part, whole, i) != i) return null;
+ var end = i;
+ while (end < range(t, part)[1] and folds(t, part, whole, end)) end += 1;
+ return std.fmt.bufPrint(buf, "+{d}", .{end - i}) catch unreachable; // a count fits
+ }
const word = wordOf(t, i, buf);
if (part != .newest or word.len <= newest_cells) return word;
const tab = 8; // a step's word holds no tab
@@ -455,7 +567,7 @@ fn wordIn(t: *const Trail, part: Part, whole: usize, i: usize, buf: *[max_text +
/// The back steps' words, each with the separator after it (before the
/// path), or the forward steps', each with one before it (after the path),
-/// the folded ones as one `+N` (`foldOf`); out of rest (`newest`) the
+/// each run of folded ones as one `+N` (`folds`); out of rest (`newest`) the
/// owner's and the newest's.
pub fn write(t: *const Trail, part: Part, whole: usize, w: *std.Io.Writer) std.Io.Writer.Error!void {
var buf: [max_text + 16]u8 = undefined;
@@ -482,7 +594,7 @@ pub fn bytes(t: *const Trail, part: Part, whole: usize) usize {
/// The back step `n` and N walk (Pick.walkList, Prompt): the newest list
/// or search; its word is underlined (UX D8).
pub fn walked(t: *const Trail) ?u8 {
- var i: usize = t.cur;
+ var i: usize = t.backs();
while (i > 0) {
i -= 1;
if (t.steps[i] == .list or t.steps[i] == .search) return @intCast(i);
@@ -503,21 +615,18 @@ pub fn outOfRest(p: *const Pardes, pane: *const Pane) bool {
pub fn spanOf(t: *const Trail, i: usize, whole: usize) [2]usize {
var buf: [max_text + 16]u8 = undefined;
var cut: [max_text + 16]u8 = undefined;
+ const at = if (folds(t, .back, whole, i)) runStart(t, .back, whole, i) else i;
var x: usize = 0;
- for (0..i) |j| if (wordIn(t, .back, whole, j, &buf, &cut)) |word| {
+ for (0..at) |j| if (wordIn(t, .back, whole, j, &buf, &cut)) |word| {
x += word.len + sep.len;
};
- const fold = foldOf(t, .back, whole);
- const at = if (i >= fold[0] and i < fold[1]) fold[0] else i;
- if (at < i) return spanOf(t, at, whole);
- const word: []const u8 = wordIn(t, .back, whole, i, &buf, &cut) orelse "";
+ const word: []const u8 = wordIn(t, .back, whole, at, &buf, &cut) orelse "";
return .{ x, x + word.len };
}
-/// Whether back step `i` is in the fold's `+N`.
+/// Whether back step `i` is in a fold's `+N`.
pub fn isFolded(t: *const Trail, i: usize, whole: usize) bool {
- const fold = foldOf(t, .back, whole);
- return i >= fold[0] and i < fold[1];
+ return folds(t, .back, whole, i);
}
/// The step whose word in `part` is at byte `off` of what `write` wrote
@@ -527,12 +636,17 @@ pub fn stepAt(t: *const Trail, part: Part, whole: usize, off: usize) ?u8 {
var cut: [max_text + 16]u8 = undefined;
var x: usize = 0;
const r = range(t, part);
- const fold = foldOf(t, part, whole);
for (r[0]..r[1]) |i| {
const word = wordIn(t, part, whole, i, &buf, &cut) orelse continue;
if (part == .forward) x += sep.len;
// A fold's `+N` is the step nearest the path of those it holds.
- if (off >= x and off < x + word.len) return @intCast(if (i == fold[0] and fold[0] < fold[1]) (if (part == .back) fold[1] - 1 else fold[0]) else i);
+ if (off >= x and off < x + word.len) {
+ var near = i;
+ if (part == .back and folds(t, part, whole, i)) while (near + 1 < r[1] and folds(t, part, whole, near + 1)) {
+ near += 1;
+ };
+ return @intCast(near);
+ }
x += word.len;
if (part != .forward) x += sep.len;
}
@@ -550,7 +664,7 @@ 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 => |w| pardes.Pick.reopen(p, id, w.index),
+ .list => |w| pardes.Pick.reopen(p, id, w.index, null),
.search => pardes.Prompt.lookWord(p, id),
.recipe => pardes.Prompt.lookRecipe(p, id),
}
@@ -867,14 +981,18 @@ test "the walk drawn with a picker's list and the notice row (walk UI G 2e, SPEC
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
// The reader's tag in the reading tint, the held one's not; the notice
- // row, nothing said, where the reader's caret is.
+ // row says what Ctrl-o goes back to (UX L'1), and with nothing said,
+ // where the reader's caret is.
try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().tag_reading_bg }, try tagGroundOf(p, &arena, rd));
try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = p.chromeTheme().tag_reading_bg }, try tagGroundOf(p, &arena, f.held)));
- const s = try p.render(arena.allocator());
- const foot = s.region(.notice_row, pardes.Region.none).?.rect;
- var row: std.ArrayList(u8) = .empty;
- for (0..s.cols) |x| try row.appendSlice(arena.allocator(), s.at(@intCast(x), foot.y).grapheme());
- try std.testing.expect(std.mem.indexOf(u8, row.items, try std.fmt.bufPrint(&want, "{s}/place.zig:8", .{f.dir})) != null);
+ for ([_][]const u8{ "C-o back to Refs 1/2", try std.fmt.bufPrint(&want, "{s}/place.zig:8", .{f.dir}) }) |said| {
+ const s = try p.render(arena.allocator());
+ const foot = s.region(.notice_row, pardes.Region.none).?.rect;
+ var row: std.ArrayList(u8) = .empty;
+ for (0..s.cols) |x| try row.appendSlice(arena.allocator(), s.at(@intCast(x), foot.y).grapheme());
+ try std.testing.expect(std.mem.indexOf(u8, row.items, said) != null);
+ _ = p.messages.retire(&.{.echo});
+ }
// n: the list's next place, in place of the current step.
typeKeys(p, "n");
p.sync();
@@ -1320,3 +1438,74 @@ test "a walk step never closes a file with unsaved changes: a reading pane chang
try std.testing.expectEqualStrings("changed\n", kept.file.?.content);
try std.testing.expect(kept.trail.held);
}
+
+test "the fold takes places alone (UX L'1): a list's and a search's words are never in a `+N`, a run of places between them each its own; where the tag keeps its newest step alone, older lists fold with the places, the newest list never" {
+ const Make = struct {
+ fn place(line: u32) Step {
+ var at: Place = .{ .line = line, .col = 1 };
+ at.path.set("/x/a.zig");
+ return .{ .place = at };
+ }
+ fn list(text: []const u8) Step {
+ var w: Word = .{};
+ w.text.set(text);
+ return .{ .list = w };
+ }
+ fn written(t: *const Trail, part: Part, whole: usize, out: []u8) ![]const u8 {
+ var w: std.Io.Writer = .fixed(out);
+ try t.write(part, whole, &w);
+ return w.buffered();
+ }
+ };
+ var out: [1024]u8 = undefined;
+ var t: Trail = .{};
+ for ([_]Step{ Make.place(1), Make.place(2), Make.list("A 1/2"), Make.place(3), Make.place(4), Make.place(5), Make.place(6) }) |s| push(&t, s);
+ t.cur = 6;
+ try std.testing.expectEqualStrings("+2 › A 1/2 › a.zig:3 › a.zig:4 › a.zig:5 › ", try Make.written(&t, .back, 3, &out));
+ try std.testing.expectEqualStrings("+2 › A 1/2 › +2 › a.zig:5 › ", try Make.written(&t, .back, 1, &out));
+ // Each `+N` is its run's: a click on the second goes to its newest.
+ try std.testing.expectEqual(@as(?u8, 1), t.stepAt(.back, 1, 0));
+ try std.testing.expectEqual(@as(?u8, 4), t.stepAt(.back, 1, "+2 › A 1/2 › ".len));
+ try std.testing.expectEqualDeep([2]usize{ "+2 › A 1/2 › ".len, "+2 › A 1/2 › +2".len }, t.spanOf(3, 1));
+ try std.testing.expect(t.isFolded(4, 1) and !t.isFolded(2, 1) and !t.isFolded(5, 1));
+ // Two lists: with the newest step alone the older folds, the newer not.
+ t = .{};
+ for ([_]Step{ Make.place(1), Make.list("A 1/2"), Make.place(2), Make.list("B 1/1"), Make.place(3), Make.place(4) }) |s| push(&t, s);
+ t.cur = 5;
+ try std.testing.expectEqualStrings("+3 › B 1/1 › a.zig:3 › ", try Make.written(&t, .back, 1, &out));
+ try std.testing.expectEqualStrings("+1 › A 1/2 › a.zig:2 › B 1/1 › a.zig:3 › ", try Make.written(&t, .back, 3, &out));
+ // A search's word never folds; forward, the places past two alone.
+ t = .{};
+ var s: Search = .{};
+ s.text.set("/s/ 1/1");
+ for ([_]Step{ Make.place(1), Make.place(2), .{ .search = s }, Make.place(3), Make.place(4), Make.place(5), Make.list("C 1/1"), Make.place(6), Make.place(7) }) |x| push(&t, x);
+ t.cur = 4;
+ try std.testing.expectEqualStrings("+2 › /s/ 1/1 › a.zig:3 › ", try Make.written(&t, .back, 1, &out));
+ try std.testing.expectEqualStrings(" › a.zig:5 › C 1/1 › +2", try Make.written(&t, .forward, 1, &out));
+}
+
+test "a held pane walks its own words (UX L'1): Ctrl-o onto its search's word puts the caret where the search started, its places lit; past it, the jump list's" {
+ var f: Fixture = .{ .p = undefined, .tmp = undefined };
+ try f.init(60);
+ defer f.deinit();
+ const p = f.p;
+ const held = p.panes[f.held].?;
+ pardes.look.focusPaneLine(p, f.held, .{ .line = 20, .col = 3 }, .center);
+ typeKeys(p, "/line 9");
+ p.update(.{ .key = .{ .cp = pardes.Key.enter } });
+ p.sync();
+ try std.testing.expectEqual(@as(i32, 89), held.body.cur_row);
+ try std.testing.expect(held.trail.n == 1 and held.trail.cur == 1 and held.trail.steps[0] == .search);
+ try std.testing.expectEqualStrings("C-o back to /line 9/ 2/11", p.messages.headline().?.words());
+ held.places.clear(p.gpa);
+ p.update(.{ .key = .{ .cp = 'o', .ctrl = true } });
+ p.sync();
+ try std.testing.expectEqual(@as(usize, f.held), p.view().active);
+ try std.testing.expectEqual(@as(i32, 19), held.body.cur_row);
+ try std.testing.expectEqual(@as(i32, 2), held.body.cur_col);
+ try std.testing.expectEqual(@as(u8, 0), held.trail.cur);
+ try std.testing.expect(held.places.shows(held) and std.mem.eql(u8, held.places.pattern, "line 9"));
+ // Its word still before its path, the search's.
+ try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, held), "/line 9/ "));
+ try std.testing.expect(!walkBy(p, f.held, -1));
+}
diff --git a/core/draw.zig b/core/draw.zig
index 2553d5be..b666fc15 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -1122,11 +1122,11 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
if (pane.file != null and pane.trail.n > 0 and !pardes.Trail.outOfRest(p, pane)) {
const kept = tagline.folded(p, pane).whole;
const t = &pane.trail;
- const first: usize = @intFromBool(t.steps[0] == .owner);
- if (t.isFolded(first, kept)) {
- const fold = t.spanOf(first, kept);
+ // Each run of folded places' `+N` (UX L'1: words never fold).
+ for (0..t.backs()) |i| if (t.isFolded(i, kept) and !(i > 0 and t.isFolded(i - 1, kept))) {
+ const fold = t.spanOf(i, kept);
inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, fold[0], @min(fold[1], first_line.len), inks.dim, false);
- }
+ };
if (t.walked()) |i| if (!t.isFolded(i, kept)) {
const word = t.spanOf(i, kept);
inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, word[0], @min(word[1], first_line.len), chrome.roles.key, true);
diff --git a/test/perf.zig b/test/perf.zig
index 00a5524a..2ea666c4 100644
--- a/test/perf.zig
+++ b/test/perf.zig
@@ -86,12 +86,16 @@ const Op = enum {
/// the tag states' keys compare with (key-down's frames each draw
/// another place of the file).
rest_keys,
+ /// Ctrl-o from a list's landing onto its word (UX L'1): the list
+ /// reopened as it was left, its head and band drawn in the key's frame;
+ /// Esc back to rest and its frame (two keys, two frames).
+ walk_pop,
/// Run only when named (`--op`): a full run, its cells and the sums a
/// gate takes over them (perfops' "terminal on all") are as before.
fn named(o: Op) bool {
return switch (o) {
- .spc, .spc_down, .help_type, .describe, .rest_keys => true,
+ .spc, .spc_down, .help_type, .describe, .rest_keys, .walk_pop => true,
else => false,
};
}
@@ -118,6 +122,7 @@ const Op = enum {
.help_type => "help-type",
.describe => "describe",
.rest_keys => "rest-keys",
+ .walk_pop => "walk-pop",
};
}
};
@@ -622,7 +627,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u
switch (op) {
.image_frame => return measureImage(std.fs.path.dirname(path).?, samples, warmup),
.client_key_down, .client_edit_char, .client_delete_undo => return measureClient(op, path, reps),
- .spc, .spc_down, .help_type, .describe, .rest_keys => return measureTag(op, path, reps),
+ .spc, .spc_down, .help_type, .describe, .rest_keys, .walk_pop => return measureTag(op, path, reps),
else => {},
}
if (op == .open) {
@@ -677,7 +682,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u
const wheel_row = rect.y + pardes.BOX_H;
const t0 = nowNs();
switch (op) {
- .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys => unreachable,
+ .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys, .walk_pop => unreachable,
.render, .deep_selection => {},
.key_down => core.update(.{ .key = .{ .cp = 'j', .text = "j" } }),
.key_right => core.update(.{ .key = .{ .cp = 'l', .text = "l" } }),
@@ -691,7 +696,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u
_ = try frame(core);
const dt = nowNs() -| t0;
switch (op) {
- .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys => unreachable,
+ .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys, .walk_pop => unreachable,
.body_write => if (pane.file.?.content.len != before.len + 8 * body_chunk.len) return error.BodyWriteWasNotAppended,
.body_appends => if (pane.file.?.content.len != before.len + append_count * append_chunk_len) return error.BodyAppendsWereNotAppended,
.render, .deep_selection => if (pane.body.cur_row != before.row or pane.body.cur_col != before.col or pane.file.?.content.len != before.len)
@@ -790,8 +795,17 @@ fn measureTag(op: Op, path: []const u8, reps: usize) !Cell {
pump(core);
const id = filePane(core) orelse return error.OpenDidNotOpenFile;
core.view().active = id;
+ // A list of two places in the file, landed on its first (a reading
+ // pane's step): the list's word in its trail before the place.
+ if (op == .walk_pop) {
+ core.settings.jumps = .walk;
+ const rows = try std.fmt.allocPrint(gpa, "{s}:10:1 a\n{s}:20:1 b\n", .{ path, path });
+ defer gpa.free(rows);
+ pardes.Pick.open(core, id, .list, "Refs", "", rows);
+ }
const enter: []const Key = switch (op) {
.spc, .rest_keys => &.{},
+ .walk_pop => &.{.{ .cp = Key.enter }},
.spc_down => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = Key.down } },
.help_type => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = '?', .text = "?" } },
.describe => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = 'h', .text = "h" }, .{ .cp = 'k', .text = "k" } },
@@ -806,8 +820,11 @@ fn measureTag(op: Op, path: []const u8, reps: usize) !Cell {
.help_type => &.{ .{ .cp = 'e', .text = "e" }, .{ .cp = Key.backspace } },
.describe => &.{ .{ .cp = 'g', .text = "g" }, .{ .cp = 'd', .text = "d" } },
.rest_keys => &.{ .{ .cp = 'j', .text = "j" }, .{ .cp = 'k', .text = "k" } },
+ .walk_pop => &.{ .{ .cp = 'o', .ctrl = true }, .{ .cp = Key.escape } },
else => unreachable,
};
+ const landed = core.panes[id].?.trail.cur;
+ if (op == .walk_pop and (landed == 0 or core.panes[id].?.trail.steps[landed - 1] != .list)) return error.ListDidNotLand;
const s = &core.view().tag_state;
for (0..warmup + samples.len) |n| {
const t0 = nowNs();
@@ -822,6 +839,8 @@ fn measureTag(op: Op, path: []const u8, reps: usize) !Cell {
if (!pardes.TagState.shown(core, core.view())) return error.LevelNotShown;
_ = try frame(core);
}
+ // The list reopened by the key itself, drawn in its frame.
+ if (op == .walk_pop and k.ctrl and pardes.Pick.live(core) == null) return error.ListNotReopened;
}
const dt = nowNs() -| t0;
const held = switch (op) {
@@ -830,6 +849,7 @@ fn measureTag(op: Op, path: []const u8, reps: usize) !Cell {
.help_type => s.kind == .help and s.field.len == 0 and s.nhits > 0,
.describe => s.kind == .describe and s.found,
.rest_keys => s.kind == .rest and s.root == null and core.panes[id].?.body.cur_row == 0,
+ .walk_pop => s.kind == .rest and core.panes[id].?.trail.cur == landed and core.panes[id].?.body.cur_row == 9,
else => unreachable,
};
if (!held) return error.TagStateLost;
diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden
index e9a50dec..82686991 100644
--- a/test/snapshots/find.golden
+++ b/test/snapshots/find.golden
@@ -72,7 +72,7 @@
|7:
|8:
|9:
-|40: ✓ /tmp/pardes-snap/find/cwd/here.txt Find 1 message · SPC h m
+|40: ✓ C-o back to Find zqm 2/3 1 message · SPC h m
== snap nomatch grid=120x41 cursor=30,2
|2: ^ Find zqm 2/3 › ␣ f Find zzqq 0
|3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist
diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden
index 8fbf0221..6a70d3c4 100644
--- a/test/snapshots/fsearch.golden
+++ b/test/snapshots/fsearch.golden
@@ -113,7 +113,7 @@
|27: 11 l11
|28: 12 l12
|29:
-|30: · @p1 a copy of the terminal's text: Tab or B2 runs it; what the program draws next replaces it (Ctrl-b types to the program) 1 message · SPC h m
+|30: ✓ C-o back to /MARK/ 2/3 1 message · SPC h m
== snap n grid=180x31 cursor=97,27
|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › +1 › /MARK/ 3/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse Foll
|18: g.txt 1 l1