diff options
Diffstat (limited to 'core/Pick.zig')
| -rw-r--r-- | core/Pick.zig | 59 |
1 files changed, 52 insertions, 7 deletions
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. |
