From b77eac2511cb247ebae07494bbb13b2e6a1139ab Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 20:13:20 -0300 Subject: Pick: a picker unrolls in the tag of the pane its Enter lands in (walk UI, pick-ui SPEC.md §3.5, §5.1-§5.3, item 1 of line D): core/Pick.zig, a picker the session's (Pardes.picks, a ring of max_lists 8, each named by a serial from the panes' counter so the disk engine's target names it as it names a pane, Stream.receive giving it its batches through Query.take, now taking either), live in a view's tag as TagState kind pick (TagState.pick its serial, host its landing pane: the asking pane when it reads, else its reader, else a pane made for it where its reader would go, an empty +Preview until the preview fills it, taken away by Esc); its sources Query.zig's producers re-presented: Find's listing from the disk engine's worker and Recent, Panes, Symbols (Query.gather, the name gathering startSource did, now shared), the jump list (Output.jumpsText, what +Jumps lists) and a list's rows handed over (a language server's answer, titled by its word), all scored by Names a frame's count at a time; Grep's lines from the worker after its pause, All the places each open text finds (as Query's All); the head ` ␣ f Find pick 3/6 ⋯` (key cells from the source's leader keys, the word, the field, cursor/total, ⋯ while scoring or searching) and a second row of the other sources' words under spines continued from the key cells (TagState.Head.cells counts the second row's spines, which Band.findSpines hangs the band from); the band's rows eleven around the cursor, made in the frame's arena for the rows shown only (O(rows shown): a Find of 50k paths makes 11 rows a frame), a place prefix in the name's tint, a path's directory dimmed, matches in the match tint; the preview is the landing pane's body: the current row's file at its line (a Grep's matches lit as its places), taken from an open pane's text or read, on the frame after the cursor stood (never on the key that moved it: Pick.busy asks the frame), a reading pane's own text set aside meanwhile (Pick.aside) and put back when it rolls up, a twinned text never previewed in; TagState.toRest rolls a live picker up first, whoever puts the tag to rest; A's API: TagState.Kind pick and its pick field, Band.takes/of's pick arm, Band.Row mark/pre/faint (drawn in draw.zig joinBand), Band.place holding a step to the band's width, TagState.point on a picker's row; TEST FIRST: Pick.zig "a picker from a held pane unrolls in a reader made for it ..." and "a picker from a reading pane unrolls in that pane, its own text set aside while it previews and back on Esc"; core-test 1014/1180 (166 skipped), 0 failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Pick.zig | 785 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 785 insertions(+) create mode 100644 core/Pick.zig (limited to 'core/Pick.zig') diff --git a/core/Pick.zig b/core/Pick.zig new file mode 100644 index 00000000..30cf74ab --- /dev/null +++ b/core/Pick.zig @@ -0,0 +1,785 @@ +//! A picker (pick-ui SPEC.md §5, direction E): a list of places, panes or +//! names unrolled in the tag of the pane its Enter lands in (§3.5): the +//! asking pane when it reads, else its reader, made for the picker when it +//! has none and taken away again by Esc. Its query is typed in that tag's +//! field (TagState.field), its rows hang in the band under it (Band.zig) +//! eleven at a time around the cursor, and that pane's body is the preview: +//! the current row's file at its line, its own text set aside meanwhile and +//! put back when the picker rolls up. +//! +//! The rows are Query.zig's producers', re-presented: names scored by +//! Names.zig a frame's count at a time (Find's listing from the disk +//! engine's worker, Recent, Panes, the asking text's declarations, the +//! rows a language server answered, the jump list), Grep's lines from the +//! disk engine's worker (Stream.zig: its pause, its cap). A frame makes +//! only the rows it shows, in its arena. +//! +//! A picker is the session's, named by a serial drawn from the panes' +//! counter (`id`), so the disk engine's `target` names it as it names a +//! pane; one is live in a view's tag (TagState.pick), and the last +//! `max_lists` are kept after they roll up. +const Pick = @This(); + +const std = @import("std"); +const pardes = @import("root.zig"); +const config = @import("config.zig"); +const layout = @import("layout.zig"); +const look = @import("look.zig"); +const panes = @import("panes.zig"); +const filesystem = @import("fs.zig"); +const exec = @import("exec.zig"); +const bindings = @import("bindings.zig"); +const Kind = @import("Kind.zig"); +const Names = @import("Names.zig"); +const Stream = @import("Stream.zig"); +const Trail = @import("Trail.zig"); +const TagState = @import("TagState.zig"); +const Band = @import("Band.zig"); +const Query = panes.Query; +const File = panes.File; +const Output = panes.Output; +const Pardes = pardes.Pardes; +const Pane = panes.Pane; +const Key = pardes.Key; + +/// What a picker lists (SPEC §5.1, the sources pardes has): the files +/// under the asking pane's directory, the lines of them holding the +/// query, the files opened lately, the panes, the asking text's +/// declarations, the lines holding the query in every open pane (All, its +/// places in each), the jump list, and rows handed over (a language +/// server's answer), titled by their word. +pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list }; + +/// Each source's word in the tag and the leader keys of the builtin that +/// opens it, its key cells (`␣ f Find`). +const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8 }).init(.{ + .find = .{ .word = "Find", .keys = "f" }, + .grep = .{ .word = "Grep", .keys = "f" }, + .recent = .{ .word = "Recent", .keys = "f" }, + .panes = .{ .word = "Panes", .keys = "b" }, + .symbols = .{ .word = "Symbols", .keys = "s" }, + .all = .{ .word = "All", .keys = "" }, + .jumplist = .{ .word = "Jumplist", .keys = "j" }, + .list = .{ .word = "List", .keys = "" }, +}); + +/// The pickers kept after they roll up, for their list words and Resume. +pub const max_lists = 8; + +/// Its serial: the disk engine's target, a list word's index. +id: u32, +source: Source, +/// Its word, `Find`, or a list's own (`Refs`). +word: Kind.Buf(24) = .{}, +/// The leader keys under which its builtin is, drawn as key cells. +keys: Kind.Buf(4) = .{}, +/// Where Find and Grep look; what the rows' paths are relative to. +dir: Kind.Buf(4096) = .{}, +/// The pane that asked, and the one its Enter lands in, by serial. +owner: u32 = 0, +landing: u32 = 0, +/// The landing pane was made for it: Esc takes it away. +made: bool = false, +/// Unrolled in a view's tag now. +unrolled: bool = false, +names: Names = .{}, +/// A Grep's lines, as the disk engine sends them (Query.take). +found: std.ArrayList(Query.Found) = .empty, +found_bytes: std.ArrayList(u8) = .empty, +/// A list's rows, as they were handed over (`path:line:col text`). +rows: []u8 = &.{}, +/// The query and the cursor as it rolled up (live, they are its view's +/// field and cursor). +query: Kind.Buf(256) = .{}, +at: u32 = 0, +/// The landing pane's own text while its body previews (a reading pane: +/// put back when the picker rolls up), and its caret then. +aside: ?File.State = null, +aside_row: i32 = 0, +aside_col: i32 = 0, +/// The row the preview shows (`no_row`: none yet); asked again on the +/// frame after the cursor moves, never on the key that moved it. +shown: u32 = no_row, +fed: u64 = 0, + +const no_row = std.math.maxInt(u32); + +pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void { + pk.names.deinit(gpa); + pk.found.deinit(gpa); + pk.found_bytes.deinit(gpa); + gpa.free(pk.rows); +} + +/// Picker `id`, kept or live. +pub fn byId(p: *const Pardes, id: u32) ?*Pick { + if (id == 0) return null; + for (p.picks) |slot| if (slot) |pk| if (pk.id == id) return pk; + return null; +} + +/// The picker live in the live view's tag. +pub fn live(p: *const Pardes) ?*Pick { + const s = &p.view().tag_state; + if (s.kind != .pick) return null; + const pk = byId(p, s.pick) orelse return null; + return if (pk.unrolled) pk else null; +} + +/// A picker of `source` asked from pane `from`, unrolled in the tag of the +/// pane its Enter will land in (SPEC §3.5), its field `query`. `rows` are +/// a list's (`source` `list`, titled `word`). +pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []const u8, rows: []const u8) void { + const asker = p.panes[from] orelse return; + TagState.toRest(p); + const pk = make(p, source) catch |err| return p.reportError(.at(from), "pick", err); + pk.word.set(if (word.len > 0) word else words.get(source).word); + pk.keys.set(words.get(source).keys); + pk.dir.set(Pardes.paneDir(asker)); + pk.owner = asker.serial; + pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err); + const landing = landingFor(p, from) catch |err| return p.reportError(.at(from), "pick", err); + // The keyboard stays where it was: the landing pane is the tag's host. + p.view().active = from; + pk.landing = p.panes[landing].?.serial; + pk.made = landing != from and Trail.readerOf(p, asker) != landing and !Trail.reading(p, asker); + unroll(p, pk, query); + start(p, pk); + filter(p, pk); +} + +/// A new picker in the ring, the oldest kept one dropped for it. +fn make(p: *Pardes, source: Source) !*Pick { + var slot: ?usize = null; + for (p.picks, 0..) |s, i| if (s == null) { + slot = i; + break; + }; + if (slot == null) { + // The oldest not live. + var oldest: ?usize = null; + for (p.picks, 0..) |s, i| if (s) |pk| if (!pk.unrolled and (oldest == null or pk.id < p.picks[oldest.?].?.id)) { + oldest = i; + }; + const i = oldest orelse return error.NoPickerSlots; + p.picks[i].?.deinit(p.gpa); + p.gpa.destroy(p.picks[i].?); + p.picks[i] = null; + slot = i; + } + const pk = try p.gpa.create(Pick); + p.next_serial += 1; + pk.* = .{ .id = p.next_serial, .source = source }; + p.picks[slot.?] = pk; + return pk; +} + +/// The pane a picker from pane `from` lands in: `from` when it reads; its +/// reader when it is held and has one; else a pane made under it as its +/// reader would be, empty until the preview fills it. +fn landingFor(p: *Pardes, from: usize) !usize { + const asker = p.panes[from].?; + if (Trail.reading(p, asker)) return from; + if (Trail.readerOf(p, asker)) |r| return r; + const free = p.freeSlot() orelse return error.NoPaneSlots; + const content = try p.gpa.dupe(u8, ""); + errdefer p.gpa.free(content); + _ = try Output.open(p, free, Pardes.paneDir(asker), .preview, "", content); + layout.placeNew(p, from, from, free, .reader); + layout.compute(p); + return free; +} + +/// Picker `pk` live in the live view's tag: its host its landing pane, its +/// field `query`, the cursor where it was. +fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void { + const v = p.view(); + const s = &v.tag_state; + s.kind = .pick; + s.pick = pk.id; + s.host = pk.landing; + s.field.set(query); + s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) }; + pk.unrolled = true; + pk.shown = no_row; + if (p.paneBySerial(pk.landing)) |id| s.previewing.set(id); +} + +/// Its source begun: the names gathered, a listing started. +fn start(p: *Pardes, pk: *Pick) void { + pk.names.reset(); + pk.found.clearRetainingCapacity(); + pk.found_bytes.clearRetainingCapacity(); + const dir = pk.dir.slice(); + switch (pk.source) { + .find => { + Stream.query(p, pk.id, .files, "", dir, .now) catch |err| return p.reportError(.at(p.view().active), "pick", err); + if (p.fs.serving) Stream.step(p); + }, + .grep, .all => {}, + .recent => Query.gather(p, &pk.names, .recent, dir, null, null), + .panes => Query.gather(p, &pk.names, .panes, dir, null, null), + .symbols => Query.gather(p, &pk.names, .symbols, dir, null, p.paneBySerial(pk.owner)), + .jumplist => { + var out: std.Io.Writer.Allocating = .init(p.gpa); + defer out.deinit(); + Output.jumpsText(p, &out.writer) catch return; + addRows(p, pk, out.written()); + }, + .list => addRows(p, pk, pk.rows), + } +} + +/// Rows of text as names, a row each, matched whole. +fn addRows(p: *Pardes, pk: *Pick, text: []const u8) void { + var lines = std.mem.splitScalar(u8, text, '\n'); + var i: u32 = 0; + while (lines.next()) |ln| : (i += 1) { + if (ln.len == 0) continue; + pk.names.add(p.gpa, ln, 0, ln.len, 0, i) catch return; + } +} + +/// The field typed: the rows again for it. A Grep's lines are the disk +/// engine's, once the typing pauses; the names are scored a frame's count +/// at a time from here. +pub fn filter(p: *Pardes, pk: *Pick) void { + const q = std.mem.trim(u8, p.view().tag_state.field.text(), " "); + p.view().tag_state.rows.at = 0; + pk.shown = no_row; + if (pk.source == .grep) { + pk.found.clearRetainingCapacity(); + pk.found_bytes.clearRetainingCapacity(); + if (q.len > 0) { + Stream.query(p, pk.id, .grep, q, pk.dir.slice(), if (p.fs.serving) .now else .typed) catch |err| return p.reportError(.at(p.view().active), "pick", err); + if (p.fs.serving) Stream.step(p); + } else if (p.stream.target == pk.id) _ = p.stream.stop(); + return; + } + if (pk.source == .all) { + // Each open text's places, found a frame's more at a time. + for (p.panes) |slot| { + const tp = slot orelse continue; + if (!searchable(tp)) continue; + if (q.len == 0) { + if (tp.places.from == pk.id) tp.places.clear(p.gpa); + } else tp.places.search(p, tp, .list, pk.id, q, false, null, false); + } + return; + } + pk.names.typed(p.gpa, q); +} + +/// A pane whose text All searches: a file's or a list's, not a query +/// pane's nor a preview's. +fn searchable(tp: *const Pane) bool { + const f = tp.file orelse return false; + if (tp.query != null) return false; + if (f.output) |o| if (o.from == .preview) return false; + return true; +} + +/// The panes All's places are in, in the order of their serials. +fn allPanes(p: *const Pardes, pk: *const Pick, out: *[pardes.MAX_PANES]usize) []usize { + var n: usize = 0; + for (p.panes, 0..) |slot, i| if (slot) |tp| if (tp.places.from == pk.id and tp.places.shows(tp) and tp.places.hits.items.len > 0) { + out[n] = i; + n += 1; + }; + std.mem.sort(usize, out[0..n], p, struct { + fn lt(pp: *const Pardes, a: usize, b: usize) bool { + return pp.panes[a].?.serial < pp.panes[b].?.serial; + } + }.lt); + return out[0..n]; +} + +/// The disk engine's rows for picker `target` (Stream.receive). +pub fn take(p: *Pardes, target: u32, kind: Stream.Kind, rows: []const u8) bool { + const pk = byId(p, target) orelse return false; + Query.take(p, pk, kind, rows); + // A listing's names, scored as they come. + if (kind == .files) pk.names.rescore(p.gpa); + return true; +} + +/// Pane `serial`'s declarations came (Stream.receiveParse): a Symbols +/// picker asked from it gathers them. +pub fn declsArrived(p: *Pardes, serial: u32) void { + for (p.picks) |slot| if (slot) |pk| if (pk.unrolled and pk.source == .symbols and pk.owner == serial and pk.names.cands.items.len == 0) { + Query.gather(p, &pk.names, .symbols, pk.dir.slice(), null, p.paneBySerial(serial)); + pk.names.typed(p.gpa, pk.names.queryText()); + pk.names.rescore(p.gpa); + }; +} + +/// After every step: each live picker's names scored on (a frame's count), +/// and on a frame of its own after the cursor stood, the preview of the +/// current row. +pub fn produceAll(p: *Pardes, tick: bool) void { + for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) { + if (pk.names.busy()) pk.names.rescore(p.gpa); + if (tick) preview(p, pk); + }; +} + +/// The frames a live picker still owes: scoring, a preview (nextWake's). +pub fn busy(p: *const Pardes) bool { + for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) { + if (pk.names.busy() or pk.shown != p.view().tag_state.rows.at) return true; + }; + return false; +} + +// ---- the rows ---- + +/// The rows the list has now. +pub fn count(p: *const Pardes, pk: *const Pick) usize { + switch (pk.source) { + .grep => return pk.found.items.len, + .all => { + var order: [pardes.MAX_PANES]usize = undefined; + var n: usize = 0; + for (allPanes(p, pk, &order)) |i| n += p.panes[i].?.places.hits.items.len; + return n; + }, + else => return pk.names.hits.items.len, + } +} + +/// Where a row points: a place in a file, or a pane by its serial. +const Target = union(enum) { none, place: struct { path: []const u8, at: look.Spot }, pane: u32 }; + +/// Row `i` as the band shows it and what it points at, its text in +/// `arena`. +const Row = struct { text: []const u8, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none }; + +fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { + const dir = pk.dir.slice(); + if (pk.source == .all) { + var order: [pardes.MAX_PANES]usize = undefined; + var k = i; + for (allPanes(p, pk, &order)) |id| { + const tp = p.panes[id].?; + const hits = tp.places.hits.items; + if (k >= hits.len) { + k -= hits.len; + continue; + } + const f = &tp.file.?; + const h = hits[k]; + const line = @import("Places.zig").lineOf(try File.lineIndex(p.gpa, f), h.start); + const ls = File.lineStart(p.gpa, f, line); + const le = std.mem.indexOfScalarPos(u8, f.content, h.start, '\n') orelse f.content.len; + const whole = f.content[ls..le]; + const lead = whole.len - std.mem.trimStart(u8, whole, " \t").len; + const name = if (f.output == null) std.Io.Dir.path.basename(f.path) else ""; + const pre = try std.fmt.allocPrint(arena, config.pane_addr ++ "{d} {s}:{d}", .{ tp.serial, name, line + 1 }); + const text = try std.fmt.allocPrint(arena, "{s} {s}", .{ pre, whole[lead..@min(whole.len, lead + 240)] }); + var marks: std.ArrayList(u16) = .empty; + var c = h.start - ls; + while (c < h.end - ls and c >= lead and pre.len + 1 + c - lead < text.len) : (c += 1) try marks.append(arena, @intCast(pre.len + 1 + c - lead)); + const target: Target = if (f.output == null) .{ .place = .{ .path = f.path, .at = .{ .line = line + 1, .col = h.start - ls + 1 } } } else .{ .pane = tp.serial }; + return .{ .text = text, .pre = @intCast(pre.len), .marks = marks.items, .target = target }; + } + return .{ .text = "" }; + } + if (pk.source == .grep) { + const fd = pk.found.items[i]; + const name = pk.found_bytes.items[fd.path..][0..fd.path_len]; + const code = pk.found_bytes.items[fd.code..][0..fd.code_len]; + const lead = code.len - std.mem.trimStart(u8, code, " \t").len; + const pre = try std.fmt.allocPrint(arena, "{f}:{d}", .{ look.quoted(name), fd.line }); + const text = try std.fmt.allocPrint(arena, "{s} {s}", .{ pre, code[lead..] }); + var marks: std.ArrayList(u16) = .empty; + var c = fd.col; + while (c < fd.end and c >= lead and pre.len + 1 + c - lead < text.len) : (c += 1) try marks.append(arena, @intCast(pre.len + 1 + c - lead)); + const path = try std.Io.Dir.path.join(arena, &.{ dir, name }); + return .{ .text = text, .pre = @intCast(pre.len), .marks = marks.items, .target = .{ .place = .{ .path = path, .at = .{ .line = fd.line, .col = fd.col + 1 } } } }; + } + var marks: [Names.max_query * 4]u16 = undefined; + var nmarks: usize = 0; + const text = pk.names.row(i, &marks, &nmarks); + const cand = pk.names.cands.items[pk.names.hits.items[i].cand]; + var row: Row = .{ .text = text, .marks = try arena.dupe(u16, marks[0..nmarks]) }; + switch (pk.source) { + .find => { + var namebuf: [4096]u8 = undefined; + const name = if (text.len > 1 and text[0] == '"' and text[text.len - 1] == '"') look.unquoted(&namebuf, text[1 .. text.len - 1]) else text; + row.faint = @intCast(if (std.mem.lastIndexOfScalar(u8, text, '/')) |k| k + 1 else 0); + row.target = .{ .place = .{ .path = try std.Io.Dir.path.join(arena, &.{ dir, name }), .at = .{} } }; + }, + .panes => { + row.pre = cand.key -| 1; + row.dim = p.paneBySerial(cand.ref) == null; + row.target = .{ .pane = cand.ref }; + }, + .symbols => { + row.pre = 6; + const owner = p.panes[p.paneBySerial(pk.owner) orelse return row] orelse return row; + const f = owner.file orelse return row; + row.target = .{ .place = .{ .path = f.path, .at = .{ .line = cand.ref } } }; + }, + .recent, .jumplist, .list, .grep, .all => { + const t = look.parsePathLine(text); + row.pre = @intCast(t.end); + if (t.path.len == 0) return row; + const path = if (t.path[0] == '/' or t.path[0] == '@') t.path else try std.Io.Dir.path.join(arena, &.{ dir, t.path }); + row.target = .{ .place = .{ .path = path, .at = t.at } }; + }, + } + return row; +} + +// ---- the tag ---- + +/// The head of the landing pane's tag (SPEC §5.3): the key cells, the +/// source's word, the query, the count `cursor/total` and `•marked`; on a +/// second row the other sources' words, under spines from the key cells. +pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { + const pk = live(p) orelse return null; + const s = &p.view().tag_state; + var text: std.ArrayList(u8) = .empty; + var spans: std.ArrayList(TagState.Span) = .empty; + try text.append(arena, ' '); + var cells: [4][2]u32 = undefined; + var ncells: usize = 0; + // SPC's cell, then its keys': `␣ f`. + if (pk.keys.len > 0) for (0..pk.keys.len + 1) |k| { + const name = if (k == 0) "␣" else bindings.keyName(pk.keys.slice()[k - 1]); + cells[ncells] = .{ @intCast(text.items.len), @intCast(text.items.len + name.len) }; + ncells += 1; + try text.appendSlice(arena, name); + try text.append(arena, ' '); + }; + try text.appendSlice(arena, pk.word.slice()); + try text.append(arena, ' '); + const caret: u32 = @intCast(text.items.len + s.field.caret); + try text.appendSlice(arena, s.field.text()); + const n = count(p, pk); + try text.print(arena, " {d}/{d}", .{ if (n == 0) 0 else s.rows.at + 1, n }); + if (pk.names.busy() or p.stream.busyFor(pk.id)) try text.appendSlice(arena, " ⋯"); + // The second row: the spines go on through it from the key cells, + // then the other sources' words, each switching to it. + try text.append(arena, '\n'); + const prefix = try pardes.tagline.prefixIn(p, arena, pane); + const width = pardes.tagline.tagWidth(p, panes.paneIdOf(p, pane) orelse 0); + const lead = File.displayWidth(p.settings.tab, prefix) % @max(1, width); + var col: usize = 0; + for (cells[0..ncells]) |c| { + const at = lead + File.displayWidth(p.settings.tab, text.items[0..c[0]]); + while (col < at) : (col += 1) try text.append(arena, ' '); + try spans.append(arena, .{ .lo = @intCast(text.items.len), .hi = @intCast(text.items.len + "│".len), .style = .key }); + try text.appendSlice(arena, "│"); + col += 1; + } + const nspines: u8 = @intCast(spans.items.len); + try text.appendSlice(arena, if (ncells == 0) "" else " "); + var first = true; + inline for (comptime std.enums.values(Source)) |src| if (src != .list) { + if (src != pk.source) { + if (!first) try text.append(arena, ' '); + first = false; + try text.appendSlice(arena, words.get(src).word); + } + }; + for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key }); + return .{ .text = text.items, .spans = spans.items, .cells = nspines, .caret = caret }; +} + +/// The band's rows: as many as the list will show, eleven at most, from +/// what the source has (not what the query keeps: typing never moves the +/// body). +pub fn bandRows(p: *const Pardes) u16 { + const pk = live(p) orelse return 0; + const have = if (pk.source == .grep or pk.source == .all) Band.Cursor.shown else pk.names.cands.items.len; + return @intCast(@max(1, @min(Band.Cursor.shown, have))); +} + +/// The band's steps: the rows around the cursor. +pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { + const pk = live(p) orelse return &.{}; + const s = &p.view().tag_state; + const n = count(p, pk); + const out = try arena.alloc(Band.Step, 1); + if (n == 0) { + const none = try arena.alloc(Band.Row, 1); + none[0] = .{ .text = if (pk.names.busy() or p.stream.busyFor(pk.id)) "⋯" else if (s.field.len == 0 and pk.source == .grep) "type to search" else "nothing matches", .dim = true }; + out[0] = .{ .rows = none }; + return out; + } + const w = s.rows.window(@intCast(@min(n, std.math.maxInt(u16)))); + const rows = try arena.alloc(Band.Row, w.hi - w.lo); + for (rows, w.lo..) |*row, i| { + const r = try rowAt(p, pk, arena, i); + row.* = .{ .text = r.text, .on = i == s.rows.at, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i) }; + } + out[0] = .{ .rows = rows }; + return out; +} + +// ---- the preview ---- + +/// The landing pane's body showing the current row's place (SPEC §5.3): +/// a file at its line, the query's matches lit for a Grep. Its own text is +/// set aside the first time, put back when the picker rolls up. A file an +/// open pane shows is taken from it; any other is read. +fn preview(p: *Pardes, pk: *Pick) void { + const s = &p.view().tag_state; + if (pk.shown == s.rows.at) return; + pk.shown = s.rows.at; + if (count(p, pk) == 0) return; + var frame = std.heap.ArenaAllocator.init(p.gpa); + defer frame.deinit(); + const row = rowAt(p, pk, frame.allocator(), s.rows.at) catch return; + const place = switch (row.target) { + .place => |t| t, + else => return, + }; + const id = p.paneBySerial(pk.landing) orelse return; + const pane = p.panes[id].?; + const f = if (pane.file) |*file| file else return; + if (f.twin != 0) return; + if (!std.mem.eql(u8, f.path, place.path)) { + if (exec.kindOf(p.tape, place.path)) |kind| if (kind != .file) return; + const bytes = openText(p, place.path) orelse (p.tape.site(.preview, p.gpa, filesystem.read, .{ p, place.path }) catch return); + if (std.mem.indexOfScalar(u8, bytes[0..@min(bytes.len, 8000)], 0) != null) { + p.gpa.free(bytes); + return; + } + const path = p.gpa.dupe(u8, place.path) catch { + p.gpa.free(bytes); + return; + }; + if (pk.aside == null and !pk.made) { + const history = File.History.create(p.gpa) catch { + p.gpa.free(bytes); + p.gpa.free(path); + return; + }; + pk.aside = pane.file; + pk.aside_row = pane.body.cur_row; + pk.aside_col = pane.body.cur_col; + pane.file = .{ .path = path, .content = bytes, .output = .{ .from = .preview }, .history = history }; + } else { + const pf = &pane.file.?; + p.gpa.free(pf.path); + pf.path = path; + File.setContent(p, pf, bytes); + pf.saved_revision = pf.revision; + pf.scroll = 0; + pf.scroll_row = 0; + pf.syntax_dirty = true; + pane.places.clear(p.gpa); + } + pane.hscroll = 0; + p.sync(); + } + const keyboard = p.view().active; + defer p.view().active = keyboard; + look.clearNavigationSelection(p, pane); + const pf = &pane.file.?; + const at = place.at; + if (at.line == 0 or at.line > File.nlines(p.gpa, pf)) { + pf.scroll = 0; + pf.scroll_row = 0; + pane.body.cur_row = 0; + pane.body.cur_col = 0; + return; + } + look.focusPaneLine(p, id, at, .center); + // A Grep's matches in the file lit, as its own pane would have them. + if (pk.source == .grep) pane.places.search(p, pane, .list, pk.id, std.mem.trim(u8, s.field.text(), " "), true, null, false); +} + +/// The text of `path` as an open pane has it, copied: no read for it. +fn openText(p: *Pardes, path: []const u8) ?[]u8 { + for (p.panes) |slot| { + const tp = slot orelse continue; + const tf = tp.file orelse continue; + if (tf.output != null or !std.mem.eql(u8, tf.path, path)) continue; + return p.gpa.dupe(u8, tf.content) catch null; + } + return null; +} + +/// The landing pane as the picker found it: its own text back, or the +/// pane made for the picker taken away (`keep`: it stays, the place +/// landed on is its). +fn restore(p: *Pardes, pk: *Pick) void { + const id = p.paneBySerial(pk.landing) orelse return; + const pane = p.panes[id].?; + for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa); + if (pk.made) { + pk.made = false; + p.removePane(id, p.paneBySerial(pk.owner)) catch |err| p.reportError(.at(id), "pick", err); + return; + } + const own = pk.aside orelse return; + pk.aside = null; + File.deinit(p, pane, &pane.file.?); + pane.file = own; + pane.body.cur_row = pk.aside_row; + pane.body.cur_col = pk.aside_col; + pane.body.vsel.active = false; + p.sync(); +} + +/// The live picker rolled up (Esc, or the tag put to rest by anything): +/// its query and cursor kept for its list word and Resume, every body as +/// it was (TagState.toRest). +pub fn rollUp(p: *Pardes) void { + const pk = live(p) orelse return; + const s = &p.view().tag_state; + pk.query.set(s.field.text()); + pk.at = s.rows.at; + pk.unrolled = false; + if (p.stream.target == pk.id) _ = p.stream.stop(); + restore(p, pk); +} + +/// Every picker freed, a live one's landing pane put back first (the +/// session's end). +pub fn deinitAll(p: *Pardes) void { + for (&p.picks) |*slot| if (slot.*) |pk| { + if (pk.unrolled) { + pk.unrolled = false; + if (pk.aside) |own| if (p.paneBySerial(pk.landing)) |id| { + const pane = p.panes[id].?; + File.deinit(p, pane, &pane.file.?); + pane.file = own; + pk.aside = null; + }; + } + pk.deinit(p.gpa); + p.gpa.destroy(pk); + slot.* = null; + }; +} + +// ---- keys ---- + +/// A key in the live picker (keys.zig tagStateKey): the rows' cursor, the +/// field. Esc is the tag's (TagState.toRest rolls it up). +pub fn key(p: *Pardes, k: Key) void { + const pk = live(p) orelse return TagState.toRest(p); + const s = &p.view().tag_state; + const n: u16 = @intCast(@min(count(p, pk), std.math.maxInt(u16))); + if (s.rows.key(k, n)) return; + if (s.field.key(k)) filter(p, pk); +} + +fn testFile(p: *Pardes, tmp: *std.testing.TmpDir, name: []const u8, text: []const u8) ![]u8 { + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = text }); + var base_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = base_buf[0..try tmp.dir.realPath(std.testing.io, &base_buf)]; + return std.Io.Dir.path.join(p.gpa, &.{ dir, name }); +} + +fn tagOf(p: *Pardes, arena: std.mem.Allocator, id: usize) ![]const u8 { + return pardes.tagline.tagText(p, arena, p.panes[id].?); +} + +fn paneCount(p: *const Pardes) usize { + var n: usize = 0; + for (p.panes) |slot| n += @intFromBool(slot != null); + return n; +} + +fn settle(p: *Pardes) void { + var n: usize = 0; + while (n < 50 and (busy(p) or p.stream.busyFor(live(p).?.id))) : (n += 1) { + Stream.step(p); + p.update(.tick); + } +} + +test "a picker from a held pane unrolls in a reader made for it: its rows in the band, the body the current row's file, Esc takes the reader away" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n"); + defer p.gpa.free(a_path); + const b_path = try testFile(p, &tmp, "pick_state.zig", "//! The state a picker keeps\nconst x = 2;\n"); + defer p.gpa.free(b_path); + const held = try p.setTestFile("held\n"); + _ = held; + const asker = p.view().active; + // Held: Keep. + Trail.keep(p.panes[asker].?); + const dir = std.Io.Dir.path.dirname(a_path).?; + p.gpa.free(p.panes[asker].?.file.?.path); + p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ dir, "held.txt" }); + p.stream.engine = .walk; + const npanes = paneCount(p); + open(p, asker, .find, "", "", ""); + const pk = live(p).?; + // A reader made for it, under the asker; its tag is the picker's. + try std.testing.expectEqual(npanes + 1, paneCount(p)); + try std.testing.expect(pk.made); + const reader = p.paneBySerial(pk.landing).?; + try std.testing.expectEqual(@as(?usize, reader), TagState.hostOf(p)); + try std.testing.expectEqual(asker, p.view().active); + settle(p); + try std.testing.expectEqual(@as(usize, 2), count(p, pk)); + for ("pick") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + settle(p); + try std.testing.expectEqual(@as(usize, 1), count(p, pk)); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const tag = try tagOf(p, a, reader); + try std.testing.expect(std.mem.indexOf(u8, tag, " ␣ f Find pick 1/1\n") != null); + try std.testing.expect(std.mem.indexOf(u8, tag, "│ Grep Recent Panes Symbols All Jumplist") != null); + // The body previews the row's file, after a frame of its own. + p.update(.tick); + try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path); + _ = try p.render(a); + const r = p.view().rects[reader]; + try std.testing.expectEqualStrings("^", p.surface.at(r.x, r.y).grapheme()); + try std.testing.expect(p.panes[reader].?.band_rows >= 1); + // Esc: the reader made for it goes, the asker as it was. + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(npanes, paneCount(p)); + try std.testing.expect(live(p) == null); + try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind); + try std.testing.expectEqualStrings("pick", pk.query.slice()); +} + +test "a picker from a reading pane unrolls in that pane, its own text set aside while it previews and back on Esc" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n"); + defer p.gpa.free(a_path); + const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n"); + defer p.gpa.free(b_path); + look.lookAt(p, p.view().active, a_path); + const id = p.view().active; + try std.testing.expect(Trail.reading(p, p.panes[id].?)); + const npanes = paneCount(p); + open(p, id, .list, "Refs", "", "beta.zig:2:1 two\nalpha.zig:1:7 alpha\n"); + const pk = live(p).?; + try std.testing.expect(!pk.made); + try std.testing.expectEqual(npanes, paneCount(p)); + try std.testing.expectEqual(@as(?usize, id), TagState.hostOf(p)); + settle(p); + try std.testing.expectEqual(@as(usize, 2), count(p, pk)); + try std.testing.expectEqualStrings(b_path, p.panes[id].?.file.?.path); + try std.testing.expectEqual(@as(i32, 1), p.panes[id].?.body.cur_row); + try std.testing.expect(pk.aside != null); + // Down: the next row's file, on the frame after. + p.update(.{ .key = .{ .cp = Key.down } }); + try std.testing.expectEqualStrings(b_path, p.panes[id].?.file.?.path); + p.update(.tick); + try std.testing.expectEqualStrings(a_path, p.panes[id].?.file.?.path); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(pk.aside == null); + try std.testing.expectEqualStrings(a_path, p.panes[id].?.file.?.path); + try std.testing.expect(p.panes[id].?.file.?.output == null); + try std.testing.expectEqual(npanes, paneCount(p)); +} -- cgit v1.3 From 93160a4d7c6151fba394fd5ab51dea3b7468b937 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 20:29:22 -0300 Subject: Pick: a picker's keys (walk UI, pick-ui SPEC.md §5.4, item 2 of line D): Enter lands through the walk's open from the pane it lands in (a reading pane steps in place, a held one's reader does; the reader made for the picker is taken away first and the place opens as the held pane's reader, look.open's own), its Spot a Find row's first line, the jump list forced so Ctrl-o goes back to where it was asked; S-Enter and C-s open each picked row in a pane below; C-v in a new column (layout.newColumn, the place put there by exec_column as a column tag's New is); marked rows land the first as asked and the others below; Tab and S-Tab mark and move (Pick.marks, what each row is: a name's candidate, a Grep's line, sorted, so a frame finds a row's mark by a search over them, never a walk); M-a marks all or none; M-h the source spine as a step in the band (f g r b s / ?: Find Grep Recent Panes Symbols All, Help over the binding tree with the query, which A's TagState.openHelp takes), the query kept; C-SPC refines: the rows the query keeps become the list (a new Names of them, the old one stacked with its query, max_refine 3; a Grep's lines and All's become names, `path:line:col text`), the head `Refs alpha | w`; Backspace on an empty field undoes a refinement, else goes back to the leader level the picker's builtin is under, unrolled (as Help's Backspace); C-q keeps the rows (the marked, else all, Query.max_rows) as a +Search of text under the asking pane, its first line the word and query, each row an address a Look opens; M-p turns the preview off (the landing pane's own text back) and on; Esc rolls everything up (the tag's: TagState.toRest); a landing pane that previewed its own file has its caret and top put back; TEST FIRST: Pick.zig "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and Backspace undoes it, M-h switches source keeping the query" and "Enter lands as a walk step in the reading pane; S-Enter opens below; from a held pane the reader made for the picker becomes its reader"; core-test 1016/1182 (166 skipped), 0 failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Pick.zig | 437 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 420 insertions(+), 17 deletions(-) (limited to 'core/Pick.zig') diff --git a/core/Pick.zig b/core/Pick.zig index 30cf74ab..e3aec3c5 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -65,6 +65,10 @@ const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8 /// The pickers kept after they roll up, for their list words and Resume. pub const max_lists = 8; +/// Refinements a picker stacks (C-SPC). +pub const max_refine = 3; + +pub const replica = .{ .len = .{.{ "refined", "nrefined" }} }; /// Its serial: the disk engine's target, a list word's index. id: u32, @@ -100,11 +104,24 @@ aside_col: i32 = 0, /// The row the preview shows (`no_row`: none yet); asked again on the /// frame after the cursor moves, never on the key that moved it. shown: u32 = no_row, -fed: u64 = 0, +/// The preview on (M-p). +previews: bool = true, +/// Marked rows (Tab), by what each is (`idOf`), in order. +marks: std.ArrayList(u32) = .empty, +/// The queries refined from (C-SPC), each with the names it listed then: +/// Backspace on an empty field goes back to them. +refined: [max_refine]Refined = undefined, +nrefined: u8 = 0, +/// The band's second step: the sources to switch to (M-h). +spine: enum(u8) { rows, sources } = .rows, + +const Refined = struct { query: Kind.Buf(64) = .{}, names: Names = .{} }; const no_row = std.math.maxInt(u32); pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void { + for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(gpa); + pk.marks.deinit(gpa); pk.names.deinit(gpa); pk.found.deinit(gpa); pk.found_bytes.deinit(gpa); @@ -240,6 +257,12 @@ fn addRows(p: *Pardes, pk: *Pick, text: []const u8) void { } } +/// Its rows are names scored by the query: any source's but a live Grep's +/// or All's, and theirs once refined. +fn fuzzy(pk: *const Pick) bool { + return pk.nrefined > 0 or (pk.source != .grep and pk.source != .all); +} + /// The field typed: the rows again for it. A Grep's lines are the disk /// engine's, once the typing pauses; the names are scored a frame's count /// at a time from here. @@ -247,6 +270,7 @@ pub fn filter(p: *Pardes, pk: *Pick) void { const q = std.mem.trim(u8, p.view().tag_state.field.text(), " "); p.view().tag_state.rows.at = 0; pk.shown = no_row; + if (fuzzy(pk)) return pk.names.typed(p.gpa, q); if (pk.source == .grep) { pk.found.clearRetainingCapacity(); pk.found_bytes.clearRetainingCapacity(); @@ -256,8 +280,8 @@ pub fn filter(p: *Pardes, pk: *Pick) void { } else if (p.stream.target == pk.id) _ = p.stream.stop(); return; } - if (pk.source == .all) { - // Each open text's places, found a frame's more at a time. + { + // All: each open text's places, found a frame's more at a time. for (p.panes) |slot| { const tp = slot orelse continue; if (!searchable(tp)) continue; @@ -265,9 +289,7 @@ pub fn filter(p: *Pardes, pk: *Pick) void { if (tp.places.from == pk.id) tp.places.clear(p.gpa); } else tp.places.search(p, tp, .list, pk.id, q, false, null, false); } - return; } - pk.names.typed(p.gpa, q); } /// A pane whose text All searches: a file's or a list's, not a query @@ -335,6 +357,7 @@ pub fn busy(p: *const Pardes) bool { /// The rows the list has now. pub fn count(p: *const Pardes, pk: *const Pick) usize { + if (fuzzy(pk)) return pk.names.hits.items.len; switch (pk.source) { .grep => return pk.found.items.len, .all => { @@ -347,6 +370,21 @@ pub fn count(p: *const Pardes, pk: *const Pick) usize { } } +/// What row `i` is, kept by a mark across a new query: a name's candidate, +/// a line's place in its source. +fn idOf(pk: *const Pick, i: usize) u32 { + return if (fuzzy(pk)) pk.names.hits.items[i].cand else @intCast(i); +} + +fn marked(pk: *const Pick, id: u32) ?usize { + const at = std.sort.lowerBound(u32, pk.marks.items, id, struct { + fn order(a: u32, b: u32) std.math.Order { + return std.math.order(a, b); + } + }.order); + return if (at < pk.marks.items.len and pk.marks.items[at] == id) at else null; +} + /// Where a row points: a place in a file, or a pane by its serial. const Target = union(enum) { none, place: struct { path: []const u8, at: look.Spot }, pane: u32 }; @@ -356,7 +394,7 @@ const Row = struct { text: []const u8, pre: u16 = 0, faint: u16 = 0, dim: bool = fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { const dir = pk.dir.slice(); - if (pk.source == .all) { + if (!fuzzy(pk) and pk.source == .all) { var order: [pardes.MAX_PANES]usize = undefined; var k = i; for (allPanes(p, pk, &order)) |id| { @@ -384,7 +422,7 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { } return .{ .text = "" }; } - if (pk.source == .grep) { + if (!fuzzy(pk)) { const fd = pk.found.items[i]; const name = pk.found_bytes.items[fd.path..][0..fd.path_len]; const code = pk.found_bytes.items[fd.code..][0..fd.code_len]; @@ -407,7 +445,7 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { var namebuf: [4096]u8 = undefined; const name = if (text.len > 1 and text[0] == '"' and text[text.len - 1] == '"') look.unquoted(&namebuf, text[1 .. text.len - 1]) else text; row.faint = @intCast(if (std.mem.lastIndexOfScalar(u8, text, '/')) |k| k + 1 else 0); - row.target = .{ .place = .{ .path = try std.Io.Dir.path.join(arena, &.{ dir, name }), .at = .{} } }; + row.target = .{ .place = .{ .path = try std.Io.Dir.path.join(arena, &.{ dir, name }), .at = .{ .line = 1, .col = 1 } } }; }, .panes => { row.pre = cand.key -| 1; @@ -454,10 +492,12 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { }; try text.appendSlice(arena, pk.word.slice()); try text.append(arena, ' '); + for (pk.refined[0..pk.nrefined]) |r| try text.print(arena, "{s} | ", .{r.query.slice()}); const caret: u32 = @intCast(text.items.len + s.field.caret); try text.appendSlice(arena, s.field.text()); const n = count(p, pk); try text.print(arena, " {d}/{d}", .{ if (n == 0) 0 else s.rows.at + 1, n }); + if (pk.marks.items.len > 0) try text.print(arena, " •{d}", .{pk.marks.items.len}); if (pk.names.busy() or p.stream.busyFor(pk.id)) try text.appendSlice(arena, " ⋯"); // The second row: the spines go on through it from the key cells, // then the other sources' words, each switching to it. @@ -492,7 +532,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { /// body). pub fn bandRows(p: *const Pardes) u16 { const pk = live(p) orelse return 0; - const have = if (pk.source == .grep or pk.source == .all) Band.Cursor.shown else pk.names.cands.items.len; + const have = if (!fuzzy(pk)) Band.Cursor.shown else pk.names.cands.items.len; return @intCast(@max(1, @min(Band.Cursor.shown, have))); } @@ -501,7 +541,12 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { const pk = live(p) orelse return &.{}; const s = &p.view().tag_state; const n = count(p, pk); - const out = try arena.alloc(Band.Step, 1); + const out = try arena.alloc(Band.Step, if (pk.spine == .sources) 2 else 1); + if (pk.spine == .sources) { + const rows = try arena.alloc(Band.Row, spine_rows.len); + for (spine_rows, rows, 0..) |src, *row, i| row.* = .{ .text = try std.fmt.allocPrint(arena, "{c} {s}", .{ src.key, src.word }), .key = 1, .index = @intCast(i), .dim = src.source == pk.source }; + out[1] = .{ .rows = rows }; + } if (n == 0) { const none = try arena.alloc(Band.Row, 1); none[0] = .{ .text = if (pk.names.busy() or p.stream.busyFor(pk.id)) "⋯" else if (s.field.len == 0 and pk.source == .grep) "type to search" else "nothing matches", .dim = true }; @@ -512,7 +557,7 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { const rows = try arena.alloc(Band.Row, w.hi - w.lo); for (rows, w.lo..) |*row, i| { const r = try rowAt(p, pk, arena, i); - row.* = .{ .text = r.text, .on = i == s.rows.at, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i) }; + row.* = .{ .text = r.text, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i) }; } out[0] = .{ .rows = rows }; return out; @@ -526,7 +571,7 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { /// open pane shows is taken from it; any other is read. fn preview(p: *Pardes, pk: *Pick) void { const s = &p.view().tag_state; - if (pk.shown == s.rows.at) return; + if (pk.shown == s.rows.at or !pk.previews) return; pk.shown = s.rows.at; if (count(p, pk) == 0) return; var frame = std.heap.ArenaAllocator.init(p.gpa); @@ -604,17 +649,22 @@ fn openText(p: *Pardes, path: []const u8) ?[]u8 { } /// The landing pane as the picker found it: its own text back, or the -/// pane made for the picker taken away (`keep`: it stays, the place -/// landed on is its). +/// pane made for the picker taken away; the places it lit put out. fn restore(p: *Pardes, pk: *Pick) void { const id = p.paneBySerial(pk.landing) orelse return; - const pane = p.panes[id].?; for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa); if (pk.made) { pk.made = false; p.removePane(id, p.paneBySerial(pk.owner)) catch |err| p.reportError(.at(id), "pick", err); return; } + putBack(p, pk); +} + +/// The landing pane's own text back in it, the preview's freed. +fn putBack(p: *Pardes, pk: *Pick) void { + const id = p.paneBySerial(pk.landing) orelse return; + const pane = p.panes[id].?; const own = pk.aside orelse return; pk.aside = null; File.deinit(p, pane, &pane.file.?); @@ -659,16 +709,264 @@ pub fn deinitAll(p: *Pardes) void { // ---- keys ---- -/// A key in the live picker (keys.zig tagStateKey): the rows' cursor, the -/// field. Esc is the tag's (TagState.toRest rolls it up). +/// A key in the live picker (keys.zig tagStateKey, SPEC §5.4). Esc is +/// the tag's: TagState.toRest rolls it up. pub fn key(p: *Pardes, k: Key) void { const pk = live(p) orelse return TagState.toRest(p); const s = &p.view().tag_state; const n: u16 = @intCast(@min(count(p, pk), std.math.maxInt(u16))); + const plain = !k.ctrl and !k.alt; + const ctrl = k.ctrl and !k.alt; + const alt = k.alt and !k.ctrl; + if (pk.spine == .sources) { + pk.spine = .rows; + for (spine_rows) |src| if (plain and k.cp == src.key) return switchTo(p, pk, src.source); + return; + } + if (plain and k.cp == Key.enter) return land(p, if (k.shift) .below else .walk); + if (ctrl and k.cp == 's') return land(p, .below); + if (ctrl and k.cp == 'v') return land(p, .column); + if (plain and k.cp == Key.tab) { + if (n == 0) return; + toggle(p, pk, idOf(pk, s.rows.at)); + _ = s.rows.key(.{ .cp = if (k.shift) Key.up else Key.down }, n); + return; + } + if (alt and k.cp == 'a') return markAll(p, pk); + if (alt and k.cp == 'h') { + pk.spine = .sources; + return; + } + if (ctrl and (k.cp == ' ' or k.cp == '@')) return refine(p, pk); + if (ctrl and k.cp == 'q') return keep(p, pk); + if (alt and k.cp == 'p') { + pk.previews = !pk.previews; + pk.shown = no_row; + if (!pk.previews) putBack(p, pk); + return; + } + if (plain and k.cp == Key.backspace and s.field.len == 0) return back(p, pk); if (s.rows.key(k, n)) return; if (s.field.key(k)) filter(p, pk); } +/// The source spine (M-h): a key a source, the query kept. +const spine_rows = [_]struct { key: u8, word: []const u8, source: ?Source }{ + .{ .key = 'f', .word = "Find", .source = .find }, + .{ .key = 'g', .word = "Grep", .source = .grep }, + .{ .key = 'r', .word = "Recent", .source = .recent }, + .{ .key = 'b', .word = "Panes", .source = .panes }, + .{ .key = 's', .word = "Symbols", .source = .symbols }, + .{ .key = '/', .word = "All", .source = .all }, + .{ .key = '?', .word = "Help", .source = null }, +}; + +/// The live picker's source another (`null`: Help over the binding tree), +/// its query kept, its landing pane the same. +fn switchTo(p: *Pardes, pk: *Pick, source: ?Source) void { + const s = &p.view().tag_state; + const to = source orelse { + var query: Kind.Buf(256) = .{}; + query.set(s.field.text()); + TagState.toRest(p); + TagState.openHelp(p, null, ""); + p.view().tag_state.field.set(query.slice()); + return TagState.filter(p); + }; + if (p.stream.target == pk.id) _ = p.stream.stop(); + for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa); + for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(p.gpa); + pk.nrefined = 0; + pk.marks.clearRetainingCapacity(); + pk.source = to; + pk.word.set(words.get(to).word); + pk.keys.set(words.get(to).keys); + start(p, pk); + filter(p, pk); +} + +fn toggle(p: *Pardes, pk: *Pick, id: u32) void { + if (marked(pk, id)) |at| { + _ = pk.marks.orderedRemove(at); + return; + } + const at = std.sort.lowerBound(u32, pk.marks.items, id, struct { + fn order(a: u32, b: u32) std.math.Order { + return std.math.order(a, b); + } + }.order); + pk.marks.insert(p.gpa, at, id) catch |err| p.reportError(.at(p.view().active), "pick", err); +} + +/// Every row marked, or none when every one is. +fn markAll(p: *Pardes, pk: *Pick) void { + const n = count(p, pk); + const all = pk.marks.items.len == n; + pk.marks.clearRetainingCapacity(); + if (all) return; + pk.marks.ensureTotalCapacity(p.gpa, n) catch |err| return p.reportError(.at(p.view().active), "pick", err); + for (0..n) |i| pk.marks.appendAssumeCapacity(idOf(pk, i)); + std.mem.sort(u32, pk.marks.items, {}, std.sort.asc(u32)); +} + +/// C-SPC: the rows the query keeps become the list, the query starts +/// empty; a Grep's lines and All's become names to score from here. +fn refine(p: *Pardes, pk: *Pick) void { + const s = &p.view().tag_state; + const q = std.mem.trim(u8, s.field.text(), " "); + if (q.len == 0 or pk.nrefined == max_refine) return; + var next: Names = .{}; + if (fuzzy(pk)) { + for (pk.names.hits.items) |h| { + const c = pk.names.cands.items[h.cand]; + next.add(p.gpa, pk.names.bytes.items[c.start..][0..c.len], c.key, c.key_len, c.base, c.ref) catch break; + } + } else { + var arena = std.heap.ArenaAllocator.init(p.gpa); + defer arena.deinit(); + for (0..count(p, pk)) |i| { + _ = arena.reset(.retain_capacity); + const row = rowAt(p, pk, arena.allocator(), i) catch break; + const at = switch (row.target) { + .place => |t| t, + else => continue, + }; + const ln = std.fmt.allocPrint(arena.allocator(), "{s}:{d}:{d} {s}", .{ relative(at.path, pk.dir.slice()), at.at.line, at.at.col, row.text[@min(row.text.len, row.pre + 1)..] }) catch break; + next.add(p.gpa, ln, 0, ln.len, 0, @intCast(i)) catch break; + } + if (p.stream.target == pk.id) _ = p.stream.stop(); + for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa); + } + pk.refined[pk.nrefined] = .{ .names = pk.names }; + pk.refined[pk.nrefined].query.set(q); + pk.nrefined += 1; + pk.names = next; + pk.marks.clearRetainingCapacity(); + s.field.clear(); + filter(p, pk); +} + +fn relative(path: []const u8, dir: []const u8) []const u8 { + const d = std.mem.trimEnd(u8, dir, "/"); + if (d.len > 0 and path.len > d.len + 1 and std.mem.startsWith(u8, path, d) and path[d.len] == '/') return path[d.len + 1 ..]; + return path; +} + +/// Backspace on an empty field: the last refinement undone, its query +/// back; else back a step, to the leader's level the picker was run from. +fn back(p: *Pardes, pk: *Pick) void { + const v = p.view(); + const s = &v.tag_state; + if (pk.nrefined > 0) { + pk.nrefined -= 1; + const r = &pk.refined[pk.nrefined]; + pk.names.deinit(p.gpa); + pk.names = r.names; + pk.marks.clearRetainingCapacity(); + s.field.set(r.query.slice()); + s.rows.at = 0; + pk.shown = no_row; + // A live source's own rows again: All's places are found anew. + if (!fuzzy(pk) and pk.source == .all) filter(p, pk); + return; + } + const keys = pk.keys; + TagState.toRest(p); + if (keys.len == 0) return; + v.prefix = .leader; + @memcpy(v.leader_keys[0..keys.len], keys.slice()); + v.leader_n = @intCast(keys.len); + s.root = .leader; + s.unrolled = true; +} + +/// 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. +fn keep(p: *Pardes, pk: *Pick) void { + const s = &p.view().tag_state; + const from = p.paneBySerial(pk.owner) orelse p.view().active; + var out: std.Io.Writer.Allocating = .init(p.gpa); + defer out.deinit(); + var arena = std.heap.ArenaAllocator.init(p.gpa); + defer arena.deinit(); + out.writer.print("{s} ", .{pk.word.slice()}) catch return; + for (pk.refined[0..pk.nrefined]) |r| out.writer.print("{s} | ", .{r.query.slice()}) catch return; + out.writer.print("{s}\n", .{s.field.text()}) catch return; + var kept: usize = 0; + for (0..count(p, pk)) |i| { + if (kept == Query.max_rows) break; + if (pk.marks.items.len > 0 and marked(pk, idOf(pk, i)) == null) continue; + _ = arena.reset(.retain_capacity); + const row = rowAt(p, pk, arena.allocator(), i) catch break; + switch (row.target) { + .place => |t| if (pk.source == .symbols) + out.writer.print("{s}:{d} {s}\n", .{ std.Io.Dir.path.basename(t.path), t.at.line, std.mem.trimStart(u8, row.text, " 0123456789") }) catch break + else + out.writer.print("{s}\n", .{row.text}) catch break, + else => out.writer.print("{s}\n", .{row.text}) catch break, + } + kept += 1; + } + TagState.toRest(p); + const free = p.freeSlot() orelse return p.reportError(.at(from), "pick", error.NoPaneSlots); + const content = out.toOwnedSlice() catch |err| return p.reportError(.at(from), "pick", err); + _ = Output.open(p, free, pk.dir.slice(), .search, "", content) catch |err| { + p.gpa.free(content); + return p.reportError(.at(from), "pick", err); + }; + layout.placeNew(p, from, from, free, .doc); +} + +/// How Enter lands: a walk step, a new pane below, a new column. +const How = enum { walk, below, column }; + +/// Enter: the current row, or the marked ones, looked at from the asking +/// pane (look.open, the walk's way: a reading pane steps, a held one's +/// reader does), the first as `how` says, the others each in a pane below. +/// The list rolls into the landing pane's trail as its word (item 4). +fn land(p: *Pardes, how: How) void { + const pk = live(p) orelse return; + const s = &p.view().tag_state; + const n = count(p, pk); + if (n == 0) return; + var arena = std.heap.ArenaAllocator.init(p.gpa); + defer arena.deinit(); + const a = arena.allocator(); + var picked: std.ArrayList(Target) = .empty; + if (pk.marks.items.len == 0) { + picked.append(a, (rowAt(p, pk, a, s.rows.at) catch return).target) catch return; + } else for (0..n) |i| if (marked(pk, idOf(pk, i)) != null) { + picked.append(a, (rowAt(p, pk, a, i) catch return).target) catch return; + }; + TagState.toRest(p); + const v = p.view(); + const from = p.paneBySerial(pk.owner) orelse v.active; + v.active = from; + v.jumps.force = true; + for (picked.items, 0..) |t, k| switch (t) { + .none => {}, + .pane => |serial| if (p.paneBySerial(serial)) |tid| { + v.active = tid; + if (layout.findPane(p, tid)) |at| p.setActiveColumn(at.col); + } else { + _ = p.store.reopen(p, serial, from); + }, + .place => |at| if (k == 0 and how == .walk) { + _ = look.open(p, from, at.path, at.at, .replace); + } else if (k == 0 and how == .column) { + layout.newColumn(p, from); + const c = layout.activeColumn(p) orelse continue; + p.exec_column = c; + defer p.exec_column = null; + pardes.tagline.exitHeader(p); + _ = look.open(p, from, at.path, at.at, .below); + } else { + _ = look.open(p, from, at.path, at.at, .below); + }, + }; +} + fn testFile(p: *Pardes, tmp: *std.testing.TmpDir, name: []const u8, text: []const u8) ![]u8 { try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = text }); var base_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; @@ -748,6 +1046,111 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the try std.testing.expectEqualStrings("pick", pk.query.slice()); } +test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and Backspace undoes it, M-h switches source keeping the query" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n"); + defer p.gpa.free(a_path); + look.lookAt(p, p.view().active, a_path); + const id = p.view().active; + open(p, id, .list, "Refs", "", "alpha.zig:1:1 one\nalpha.zig:1:2 two\nbeta.zig:1:1 tree\nalpha.zig:1:4 four\n"); + const pk = live(p).?; + settle(p); + const s = &p.view().tag_state; + try std.testing.expectEqual(@as(usize, 4), count(p, pk)); + p.update(.{ .key = .{ .cp = Key.tab } }); + try std.testing.expectEqual(@as(u16, 1), s.rows.at); + p.update(.{ .key = .{ .cp = Key.tab } }); + try std.testing.expectEqual(@as(usize, 2), pk.marks.items.len); + p.update(.{ .key = .{ .cp = Key.up } }); + p.update(.{ .key = .{ .cp = Key.tab } }); + try std.testing.expectEqual(@as(usize, 1), pk.marks.items.len); + try std.testing.expectEqual(@as(u16, 2), s.rows.at); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), id), " Refs 3/4 •1\n") != null); + p.update(.{ .key = .{ .cp = 'a', .alt = true } }); + try std.testing.expectEqual(@as(usize, 4), pk.marks.items.len); + p.update(.{ .key = .{ .cp = 'a', .alt = true } }); + try std.testing.expectEqual(@as(usize, 0), pk.marks.items.len); + // C-SPC: what `alpha` keeps becomes the list; `w` then narrows it. + for ("alpha") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + settle(p); + try std.testing.expectEqual(@as(usize, 3), count(p, pk)); + p.update(.{ .key = .{ .cp = ' ', .ctrl = true } }); + try std.testing.expectEqual(@as(u8, 1), pk.nrefined); + try std.testing.expectEqual(@as(u16, 0), s.field.len); + settle(p); + try std.testing.expectEqual(@as(usize, 3), count(p, pk)); + for ("w") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + settle(p); + try std.testing.expectEqual(@as(usize, 1), count(p, pk)); + _ = frame.reset(.retain_capacity); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), id), " Refs alpha | w 1/1\n") != null); + // Backspace twice: the `w` goes, then the refinement, its query back. + p.update(.{ .key = .{ .cp = Key.backspace } }); + p.update(.{ .key = .{ .cp = Key.backspace } }); + try std.testing.expectEqual(@as(u8, 0), pk.nrefined); + try std.testing.expectEqualStrings("alpha", s.field.text()); + settle(p); + try std.testing.expectEqual(@as(usize, 3), count(p, pk)); + // M-h r: Recent, the query kept. + p.update(.{ .key = .{ .cp = 'h', .alt = true } }); + try std.testing.expect(pk.spine == .sources); + p.update(.{ .key = .{ .cp = 'r', .text = "r" } }); + try std.testing.expectEqual(Source.recent, pk.source); + try std.testing.expectEqualStrings("alpha", s.field.text()); + p.update(.{ .key = .{ .cp = Key.escape } }); +} + +test "Enter lands as a walk step in the reading pane; S-Enter opens below; from a held pane the reader made for the picker becomes its reader" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n"); + defer p.gpa.free(a_path); + const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n"); + defer p.gpa.free(b_path); + look.lookAt(p, p.view().active, a_path); + const id = p.view().active; + const npanes = paneCount(p); + open(p, id, .list, "Refs", "", "beta.zig:3:1 three\n"); + settle(p); + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expect(live(p) == null); + const here = p.panes[p.view().active].?; + try std.testing.expectEqualStrings(b_path, here.file.?.path); + try std.testing.expectEqual(@as(i32, 2), here.body.cur_row); + try std.testing.expect(here.file.?.output == null); + try std.testing.expectEqual(npanes, paneCount(p)); + // Its trail: where it was, then the place. + try std.testing.expect(here.trail.n >= 2); + // S-Enter: a pane below, the reading pane as it was. + open(p, p.view().active, .list, "Refs", "", "alpha.zig:1:7 alpha\n"); + settle(p); + p.update(.{ .key = .{ .cp = Key.enter, .shift = true } }); + try std.testing.expectEqual(npanes + 1, paneCount(p)); + try std.testing.expectEqualStrings(a_path, p.panes[p.view().active].?.file.?.path); + + // From a held pane: the reader made for the picker is taken away and + // the place opens as the held pane's reader, its trail its owner's. + const held = p.view().active; + Trail.keep(p.panes[held].?); + open(p, held, .list, "Refs", "", "beta.zig:2:1 two\n"); + const pk = live(p).?; + try std.testing.expect(pk.made); + settle(p); + p.update(.{ .key = .{ .cp = Key.enter } }); + const reader = Trail.readerOf(p, p.panes[held].?).?; + try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path); + try std.testing.expectEqual(npanes + 2, paneCount(p)); +} + test "a picker from a reading pane unrolls in that pane, its own text set aside while it previews and back on Esc" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); defer p.deinit(); -- cgit v1.3 From 441e61294268bd0bb94abfa6b1ebb4ced23e726c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 20:33:44 -0300 Subject: Pick: the act step (walk UI, pick-ui SPEC.md §5.5, item 3 of line D): M-l or M-Enter unrolls the acts beside the rows, headed by what they act on (`on 2 marked`, `on core/pick.zig`), and the head's second row says them before the sources' words (`Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent ...`); a key letter or Enter on the act's row: w Walk lands on the first picked place and queues the others (Pick.queue, the places as paths and spots), which Ctrl-i steps in the landing pane past its newest step (Pick.stepQueue, at the hook B left in Jump.jumpBy), o Look, s Split, v Newcol (Enter's three ways), g Grep a Grep picker in the picked rows' directory with the same pattern, e Edit the field a sam command (the head `Find pick | Edit s/a/b/`) run by Enter on each picked row's line in the open text that shows it (edit_cmd.run, from the last line up, a row whose file no pane shows passed over and said), y Copy the places as `path:line` lines into the unnamed register, k Keep as C-q, x Drop the picked rows as a refinement without them, d Del (the Panes list's, whose acts are Look Copy Keep Drop Del: its rows are no places) closes the picked panes and lists them again; an act's or a source's word run while the picker is live (B2 on the head's second row or on the band) is the picker's (Pick.execWord, at the head of exec.zig executeBuiltinLine; Grep, both, is the source); B3 on a picker's row lands on it and B2 runs the word with the picker live (mouse.zig bandPress: the picker's arm before A's toRest); a landing pane previewed in its own file has its caret and top put back when the picker rolls up (said in item 2's description, made here); TEST FIRST: Pick.zig "M-l unrolls the act step, which says what it acts on; Copy puts the places in the register, Drop takes the picked rows out, Walk queues the rest for C-i"; core-test 1017/1183 (166 skipped), 0 failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Jump.zig | 5 +- core/Pick.zig | 379 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- core/exec.zig | 2 + core/mouse.zig | 12 ++ 4 files changed, 369 insertions(+), 29 deletions(-) (limited to 'core/Pick.zig') diff --git a/core/Jump.zig b/core/Jump.zig index a4ecca04..5cc9d624 100644 --- a/core/Jump.zig +++ b/core/Jump.zig @@ -275,9 +275,10 @@ pub fn trackJump(p: *Pardes) void { 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 - // step, Ctrl-i is to step the Walk queue once the pickers make one; - // until then, the jump list's. + // 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; 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)) diff --git a/core/Pick.zig b/core/Pick.zig index e3aec3c5..0f9134bb 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -97,10 +97,12 @@ rows: []u8 = &.{}, query: Kind.Buf(256) = .{}, at: u32 = 0, /// The landing pane's own text while its body previews (a reading pane: -/// put back when the picker rolls up), and its caret then. +/// put back when the picker rolls up), and its caret and top then (put +/// back too when it previewed its own file, with nothing set aside). aside: ?File.State = null, aside_row: i32 = 0, aside_col: i32 = 0, +aside_top: usize = 0, /// The row the preview shows (`no_row`: none yet); asked again on the /// frame after the cursor moves, never on the key that moved it. shown: u32 = no_row, @@ -112,8 +114,19 @@ marks: std.ArrayList(u32) = .empty, /// Backspace on an empty field goes back to them. refined: [max_refine]Refined = undefined, nrefined: u8 = 0, -/// The band's second step: the sources to switch to (M-h). -spine: enum(u8) { rows, sources } = .rows, +/// The band's second step: the sources to switch to (M-h), the acts on +/// the picked rows (M-l, M-Enter); `edit`: the field is the act Edit's +/// command, the query kept in `query`. +spine: enum(u8) { rows, sources, acts, edit } = .rows, +/// The act step's cursor, among the acts offered. +act_at: u8 = 0, +/// The places Walk queued (C-i steps them in the landing pane): each a +/// path in `queue_bytes`, its line and column. +queue: std.ArrayList(Queued) = .empty, +queue_bytes: std.ArrayList(u8) = .empty, +queue_at: u32 = 0, + +pub const Queued = struct { path: u32, len: u16, line: u32, col: u32 }; const Refined = struct { query: Kind.Buf(64) = .{}, names: Names = .{} }; @@ -122,6 +135,8 @@ const no_row = std.math.maxInt(u32); pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void { for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(gpa); pk.marks.deinit(gpa); + pk.queue.deinit(gpa); + pk.queue_bytes.deinit(gpa); pk.names.deinit(gpa); pk.found.deinit(gpa); pk.found_bytes.deinit(gpa); @@ -219,7 +234,13 @@ fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void { s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) }; pk.unrolled = true; pk.shown = no_row; - if (p.paneBySerial(pk.landing)) |id| s.previewing.set(id); + if (p.paneBySerial(pk.landing)) |id| { + s.previewing.set(id); + const pane = p.panes[id].?; + pk.aside_row = pane.body.cur_row; + pk.aside_col = pane.body.cur_col; + pk.aside_top = if (pane.file) |f| f.scroll else 0; + } } /// Its source begun: the names gathered, a listing started. @@ -493,6 +514,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { try text.appendSlice(arena, pk.word.slice()); try text.append(arena, ' '); for (pk.refined[0..pk.nrefined]) |r| try text.print(arena, "{s} | ", .{r.query.slice()}); + if (pk.spine == .edit) try text.print(arena, "{s} | Edit ", .{pk.query.slice()}); const caret: u32 = @intCast(text.items.len + s.field.caret); try text.appendSlice(arena, s.field.text()); const n = count(p, pk); @@ -515,7 +537,9 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { } const nspines: u8 = @intCast(spans.items.len); try text.appendSlice(arena, if (ncells == 0) "" else " "); - var first = true; + for (acts) |act| if (offered(pk, act)) try text.print(arena, "{s} ", .{act.word}); + try text.appendSlice(arena, "|"); + var first = false; inline for (comptime std.enums.values(Source)) |src| if (src != .list) { if (src != pk.source) { if (!first) try text.append(arena, ' '); @@ -541,7 +565,8 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { const pk = live(p) orelse return &.{}; const s = &p.view().tag_state; const n = count(p, pk); - const out = try arena.alloc(Band.Step, if (pk.spine == .sources) 2 else 1); + const out = try arena.alloc(Band.Step, if (pk.spine == .sources or pk.spine == .acts) 2 else 1); + if (pk.spine == .acts) out[1] = try actStep(p, pk, arena); if (pk.spine == .sources) { const rows = try arena.alloc(Band.Row, spine_rows.len); for (spine_rows, rows, 0..) |src, *row, i| row.* = .{ .text = try std.fmt.allocPrint(arena, "{c} {s}", .{ src.key, src.word }), .key = 1, .index = @intCast(i), .dim = src.source == pk.source }; @@ -603,8 +628,6 @@ fn preview(p: *Pardes, pk: *Pick) void { return; }; pk.aside = pane.file; - pk.aside_row = pane.body.cur_row; - pk.aside_col = pane.body.cur_col; pane.file = .{ .path = path, .content = bytes, .output = .{ .from = .preview }, .history = history }; } else { const pf = &pane.file.?; @@ -665,7 +688,15 @@ fn restore(p: *Pardes, pk: *Pick) void { fn putBack(p: *Pardes, pk: *Pick) void { const id = p.paneBySerial(pk.landing) orelse return; const pane = p.panes[id].?; - const own = pk.aside orelse return; + if (pk.made) return; + const own = pk.aside orelse { + // Its own file previewed: its caret and top as they were. + look.clearNavigationSelection(p, pane); + pane.body.cur_row = pk.aside_row; + pane.body.cur_col = pk.aside_col; + if (pane.file != null) File.setTop(pane, .{ .line = pk.aside_top }); + return; + }; pk.aside = null; File.deinit(p, pane, &pane.file.?); pane.file = own; @@ -681,7 +712,8 @@ fn putBack(p: *Pardes, pk: *Pick) void { pub fn rollUp(p: *Pardes) void { const pk = live(p) orelse return; const s = &p.view().tag_state; - pk.query.set(s.field.text()); + if (pk.spine != .edit) pk.query.set(s.field.text()); + pk.spine = .rows; pk.at = s.rows.at; pk.unrolled = false; if (p.stream.target == pk.id) _ = p.stream.stop(); @@ -723,6 +755,22 @@ pub fn key(p: *Pardes, k: Key) void { for (spine_rows) |src| if (plain and k.cp == src.key) return switchTo(p, pk, src.source); return; } + if (pk.spine == .acts) return actKey(p, pk, k); + if (pk.spine == .edit) { + if (plain and k.cp == Key.enter) return editRows(p, pk); + if (plain and k.cp == Key.backspace and s.field.len == 0 or alt and k.cp == 'h') { + s.field.set(pk.query.slice()); + pk.spine = .rows; + return; + } + _ = s.field.key(k); + return; + } + if (alt and (k.cp == Key.enter or k.cp == 'l')) { + pk.spine = .acts; + pk.act_at = 0; + return; + } if (plain and k.cp == Key.enter) return land(p, if (k.shift) .below else .walk); if (ctrl and k.cp == 's') return land(p, .below); if (ctrl and k.cp == 'v') return land(p, .column); @@ -737,7 +785,7 @@ pub fn key(p: *Pardes, k: Key) void { pk.spine = .sources; return; } - if (ctrl and (k.cp == ' ' or k.cp == '@')) return refine(p, pk); + if (ctrl and (k.cp == ' ' or k.cp == '@')) return refine(p, pk, false); if (ctrl and k.cp == 'q') return keep(p, pk); if (alt and k.cp == 'p') { pk.previews = !pk.previews; @@ -811,13 +859,16 @@ fn markAll(p: *Pardes, pk: *Pick) void { /// C-SPC: the rows the query keeps become the list, the query starts /// empty; a Grep's lines and All's become names to score from here. -fn refine(p: *Pardes, pk: *Pick) void { +fn refine(p: *Pardes, pk: *Pick, drop: bool) void { const s = &p.view().tag_state; const q = std.mem.trim(u8, s.field.text(), " "); - if (q.len == 0 or pk.nrefined == max_refine) return; + if (q.len == 0 and !drop or pk.nrefined == max_refine) return; + // Dropped: the marked rows, or the current one. + const current = if (count(p, pk) > 0) idOf(pk, s.rows.at) else std.math.maxInt(u32); var next: Names = .{}; if (fuzzy(pk)) { for (pk.names.hits.items) |h| { + if (drop and (if (pk.marks.items.len > 0) marked(pk, h.cand) != null else h.cand == current)) continue; const c = pk.names.cands.items[h.cand]; next.add(p.gpa, pk.names.bytes.items[c.start..][0..c.len], c.key, c.key_len, c.base, c.ref) catch break; } @@ -825,6 +876,7 @@ fn refine(p: *Pardes, pk: *Pick) void { var arena = std.heap.ArenaAllocator.init(p.gpa); defer arena.deinit(); for (0..count(p, pk)) |i| { + if (drop and (if (pk.marks.items.len > 0) marked(pk, @intCast(i)) != null else i == current)) continue; _ = arena.reset(.retain_capacity); const row = rowAt(p, pk, arena.allocator(), i) catch break; const at = switch (row.target) { @@ -918,8 +970,9 @@ fn keep(p: *Pardes, pk: *Pick) void { layout.placeNew(p, from, from, free, .doc); } -/// How Enter lands: a walk step, a new pane below, a new column. -const How = enum { walk, below, column }; +/// How Enter lands: a walk step, a new pane below, a new column; `queue`: +/// a walk step to the first, the others queued for C-i (the act Walk). +const How = enum { walk, below, column, queue }; /// Enter: the current row, or the marked ones, looked at from the asking /// pane (look.open, the walk's way: a reading pane steps, a held one's @@ -927,24 +980,29 @@ const How = enum { walk, below, column }; /// The list rolls into the landing pane's trail as its word (item 4). fn land(p: *Pardes, how: How) void { const pk = live(p) orelse return; - const s = &p.view().tag_state; - const n = count(p, pk); - if (n == 0) return; var arena = std.heap.ArenaAllocator.init(p.gpa); defer arena.deinit(); const a = arena.allocator(); - var picked: std.ArrayList(Target) = .empty; - if (pk.marks.items.len == 0) { - picked.append(a, (rowAt(p, pk, a, s.rows.at) catch return).target) catch return; - } else for (0..n) |i| if (marked(pk, idOf(pk, i)) != null) { - picked.append(a, (rowAt(p, pk, a, i) catch return).target) catch return; + const picked = pickedRows(p, pk, a) catch return; + if (picked.len == 0) return; + // Walk: the first now, the others queued for C-i. + pk.queue.clearRetainingCapacity(); + pk.queue_bytes.clearRetainingCapacity(); + pk.queue_at = 0; + if (how == .queue) for (picked[1..]) |t| switch (t) { + .place => |at| { + const q: Queued = .{ .path = @intCast(pk.queue_bytes.items.len), .len = @intCast(@min(at.path.len, std.math.maxInt(u16))), .line = std.math.lossyCast(u32, at.at.line), .col = std.math.lossyCast(u32, at.at.col) }; + pk.queue_bytes.appendSlice(p.gpa, at.path[0..q.len]) catch break; + pk.queue.append(p.gpa, q) catch break; + }, + else => {}, }; TagState.toRest(p); const v = p.view(); const from = p.paneBySerial(pk.owner) orelse v.active; v.active = from; v.jumps.force = true; - for (picked.items, 0..) |t, k| switch (t) { + for (picked, 0..) |t, k| switch (t) { .none => {}, .pane => |serial| if (p.paneBySerial(serial)) |tid| { v.active = tid; @@ -952,7 +1010,7 @@ fn land(p: *Pardes, how: How) void { } else { _ = p.store.reopen(p, serial, from); }, - .place => |at| if (k == 0 and how == .walk) { + .place => |at| if (k == 0 and (how == .walk or how == .queue)) { _ = look.open(p, from, at.path, at.at, .replace); } else if (k == 0 and how == .column) { layout.newColumn(p, from); @@ -961,10 +1019,234 @@ fn land(p: *Pardes, how: How) void { defer p.exec_column = null; pardes.tagline.exitHeader(p); _ = look.open(p, from, at.path, at.at, .below); - } else { + } else if (how != .queue) { _ = look.open(p, from, at.path, at.at, .below); }, }; + if (how == .queue and pk.queue.items.len > 0) { + var said: Kind.Buf(64) = .{}; + p.setMessage(.at(v.active), said.print("Walk: {d} more places here, C-i for the next", .{pk.queue.items.len})); + } +} + +/// B3 on a picker's row (mouse.zig bandPress): Enter on it. +pub fn landHere(p: *Pardes) void { + const pk = live(p) orelse return; + if (pk.spine == .rows) land(p, .walk); +} + +/// The rows an act or Enter takes: the marked, else the current. +fn pickedRows(p: *Pardes, pk: *const Pick, a: std.mem.Allocator) ![]Target { + const s = &p.view().tag_state; + const n = count(p, pk); + var picked: std.ArrayList(Target) = .empty; + if (n == 0) return picked.items; + if (pk.marks.items.len == 0) { + try picked.append(a, (try rowAt(p, pk, a, s.rows.at)).target); + } else for (0..n) |i| if (marked(pk, idOf(pk, i)) != null) { + try picked.append(a, (try rowAt(p, pk, a, i)).target); + }; + return picked.items; +} + +/// C-i past a reading pane's newest step (Jump.jumpBy, SPEC §6.4): the +/// next place a Walk queued in it, through the list its trail holds last. +pub fn stepQueue(p: *Pardes, id: usize) bool { + const pane = p.panes[id] orelse return false; + const t = &pane.trail; + var i: usize = @min(t.cur, t.n); + const pk = while (i > 0) { + i -= 1; + if (t.steps[i] == .list) break byId(p, t.steps[i].list.index) orelse return false; + } else return false; + if (pk.queue_at >= pk.queue.items.len) return false; + const q = pk.queue.items[pk.queue_at]; + pk.queue_at += 1; + p.view().jumps.force = true; + _ = look.open(p, id, pk.queue_bytes.items[q.path..][0..q.len], .{ .line = q.line, .col = q.col }, .replace); + return true; +} + +// ---- acts ---- + +/// What the act step offers (SPEC §5.5): the same everywhere, but a list +/// of panes, whose rows are no places, has Look, Copy, Keep, Drop and Del. +const Act = struct { key: u8, word: []const u8, says: []const u8 }; +const acts = [_]Act{ + .{ .key = 'w', .word = "Walk", .says = "here, one by one (C-i)" }, + .{ .key = 'o', .word = "Look", .says = "open them (Enter)" }, + .{ .key = 's', .word = "Split", .says = "each in a pane below" }, + .{ .key = 'v', .word = "Newcol", .says = "in a new column" }, + .{ .key = 'g', .word = "Grep", .says = "in their directory, the same pattern" }, + .{ .key = 'e', .word = "Edit", .says = "a sam command on each line" }, + .{ .key = 'y', .word = "Copy", .says = "the places, as text" }, + .{ .key = 'k', .word = "Keep", .says = "the rows as a +Search" }, + .{ .key = 'x', .word = "Drop", .says = "the picked from the list" }, + .{ .key = 'd', .word = "Del", .says = "close those panes" }, +}; + +fn offered(pk: *const Pick, act: Act) bool { + if (pk.source == .panes) return std.mem.indexOfScalar(u8, "oykxd", act.key) != null; + return act.key != 'd'; +} + +/// The act step: what it acts on (`on 2 marked`, `on core/pick.zig`), +/// then the acts. +fn actStep(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator) !Band.Step { + var rows: std.ArrayList(Band.Row) = .empty; + const s = &p.view().tag_state; + const on = if (pk.marks.items.len > 0) + try std.fmt.allocPrint(arena, "on {d} marked", .{pk.marks.items.len}) + else if (count(p, pk) > 0) on: { + const row = try rowAt(p, pk, arena, s.rows.at); + break :on try std.fmt.allocPrint(arena, "on {s}", .{switch (row.target) { + .place => |t| relative(t.path, pk.dir.slice()), + else => row.text, + }}); + } else "on nothing"; + try rows.append(arena, .{ .text = on, .dim = true }); + var k: u8 = 0; + for (acts) |act| if (offered(pk, act)) { + try rows.append(arena, .{ .text = try std.fmt.allocPrint(arena, "{c} {s: <7} {s}", .{ act.key, act.word, act.says }), .key = 1, .on = k == pk.act_at, .index = k }); + k += 1; + }; + return .{ .rows = rows.items }; +} + +fn actKey(p: *Pardes, pk: *Pick, k: Key) void { + const plain = !k.ctrl and !k.alt; + var n: u8 = 0; + for (acts) |act| n += @intFromBool(offered(pk, act)); + if (plain and (k.cp == Key.down or k.cp == Key.up)) { + pk.act_at = if (k.cp == Key.down) (pk.act_at + 1) % n else (pk.act_at + n - 1) % n; + return; + } + var at: u8 = 0; + for (acts) |act| if (offered(pk, act)) { + if (plain and (k.cp == act.key or k.cp == Key.enter and at == pk.act_at)) return doAct(p, pk, act.key); + at += 1; + }; + // Anything else (M-h, Left): back to the rows. + pk.spine = .rows; +} + +/// Act `key` on the picked rows. +fn doAct(p: *Pardes, pk: *Pick, key_: u8) void { + const s = &p.view().tag_state; + pk.spine = .rows; + switch (key_) { + 'w' => land(p, .queue), + 'o' => land(p, .walk), + 's' => land(p, .below), + 'v' => land(p, .column), + 'k' => keep(p, pk), + 'x' => refine(p, pk, true), + 'e' => { + pk.query.set(s.field.text()); + s.field.clear(); + pk.spine = .edit; + }, + 'g' => { + var arena = std.heap.ArenaAllocator.init(p.gpa); + defer arena.deinit(); + const picked = pickedRows(p, pk, arena.allocator()) catch return; + const dir = for (picked) |t| switch (t) { + .place => |at| break std.Io.Dir.path.dirname(at.path) orelse pk.dir.slice(), + else => {}, + } else pk.dir.slice(); + const q = if (pk.source == .grep) arena.allocator().dupe(u8, s.field.text()) catch return else ""; + const where = arena.allocator().dupe(u8, dir) catch return; + const from = p.paneBySerial(pk.owner) orelse p.view().active; + TagState.toRest(p); + open(p, from, .grep, "", "", ""); + const grep = live(p) orelse return; + grep.dir.set(where); + p.view().tag_state.field.set(q); + filter(p, grep); + }, + 'y' => { + var out: std.Io.Writer.Allocating = .init(p.gpa); + defer out.deinit(); + var arena = std.heap.ArenaAllocator.init(p.gpa); + defer arena.deinit(); + const picked = pickedRows(p, pk, arena.allocator()) catch return; + for (picked) |t| switch (t) { + .place => |at| out.writer.print("{s}:{d}\n", .{ at.path, @max(1, at.at.line) }) catch return, + .pane => |serial| out.writer.print(config.pane_addr ++ "{d}\n", .{serial}) catch return, + .none => {}, + }; + p.registers.put(p.gpa, '"', out.written(), 0, 1, true) catch |err| return p.reportError(.at(p.view().active), "pick", err); + var said: Kind.Buf(64) = .{}; + p.setMessage(.at(p.view().active), said.print("Copy: {d} places into the \" register", .{picked.len})); + }, + 'd' => { + var arena = std.heap.ArenaAllocator.init(p.gpa); + defer arena.deinit(); + const picked = pickedRows(p, pk, arena.allocator()) catch return; + for (picked) |t| if (t == .pane) if (p.paneBySerial(t.pane)) |id| if (id != p.paneBySerial(pk.landing)) { + p.removePane(id, null) catch |err| p.reportError(.at(id), "pick", err); + }; + pk.marks.clearRetainingCapacity(); + start(p, pk); + filter(p, pk); + }, + else => {}, + } +} + +/// Edit's Enter: its command run on each picked row's line, in the open +/// text that shows its file (edit_cmd.zig, an undo step a line); a row +/// whose file no pane shows is passed over, and said. +fn editRows(p: *Pardes, pk: *Pick) void { + const s = &p.view().tag_state; + var arena = std.heap.ArenaAllocator.init(p.gpa); + defer arena.deinit(); + const a = arena.allocator(); + const command = a.dupe(u8, std.mem.trim(u8, s.field.text(), " ")) catch return; + const picked = pickedRows(p, pk, a) catch return; + TagState.toRest(p); + if (command.len == 0) return; + var ran: usize = 0; + // From the last line up, so an edit that adds lines moves none still to come. + var k = picked.len; + while (k > 0) { + k -= 1; + const at = switch (picked[k]) { + .place => |t| t, + else => continue, + }; + const id = for (p.panes, 0..) |slot, i| { + const tp = slot orelse continue; + const f = tp.file orelse continue; + if (f.output == null and std.mem.eql(u8, f.path, at.path)) break i; + } else continue; + @import("edit_cmd.zig").run(p, id, std.fmt.allocPrint(a, "{d} {s}", .{ @max(1, at.at.line), command }) catch return); + ran += 1; + } + var said: Kind.Buf(96) = .{}; + p.setMessage(.at(p.view().active), said.print("Edit {s}: {d} of {d} lines, in open texts", .{ command[0..@min(command.len, 40)], ran, picked.len })); +} + +/// A word of the picker's tag or band run (B2, exec.zig +/// executeBuiltinLine) while it is live: an act's word acts, a source's +/// switches to it (Grep, both, is the source); anything else is no +/// picker's. +pub fn execWord(p: *Pardes, txt: []const u8) bool { + const pk = live(p) orelse return false; + const word = std.mem.trim(u8, txt, " \t\n"); + for (spine_rows) |src| if (std.mem.eql(u8, word, src.word)) { + switchTo(p, pk, src.source); + return true; + }; + if (std.mem.eql(u8, word, "Jumplist")) { + switchTo(p, pk, .jumplist); + return true; + } + for (acts) |act| if (offered(pk, act) and std.mem.eql(u8, word, act.word)) { + doAct(p, pk, act.key); + return true; + }; + return false; } fn testFile(p: *Pardes, tmp: *std.testing.TmpDir, name: []const u8, text: []const u8) ![]u8 { @@ -1030,7 +1312,7 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the const a = frame.allocator(); const tag = try tagOf(p, a, reader); try std.testing.expect(std.mem.indexOf(u8, tag, " ␣ f Find pick 1/1\n") != null); - try std.testing.expect(std.mem.indexOf(u8, tag, "│ Grep Recent Panes Symbols All Jumplist") != null); + try std.testing.expect(std.mem.indexOf(u8, tag, "│ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist") != null); // The body previews the row's file, after a frame of its own. p.update(.tick); try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path); @@ -1151,6 +1433,49 @@ test "Enter lands as a walk step in the reading pane; S-Enter opens below; from try std.testing.expectEqual(npanes + 2, paneCount(p)); } +test "M-l unrolls the act step, which says what it acts on; Copy puts the places in the register, Drop takes the picked rows out, Walk queues the rest for C-i" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "one\ntwo\nthree\nfour\n"); + defer p.gpa.free(a_path); + look.lookAt(p, p.view().active, a_path); + const id = p.view().active; + const rows = "alpha.zig:1:1 one\nalpha.zig:2:1 two\nalpha.zig:3:1 three\nalpha.zig:4:1 four\n"; + open(p, id, .list, "Refs", "", rows); + const pk = live(p).?; + settle(p); + p.update(.{ .key = .{ .cp = 'l', .alt = true } }); + try std.testing.expect(pk.spine == .acts); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const band = (try Band.of(p, frame.allocator(), p.panes[id].?, id)).?; + try std.testing.expectEqual(@as(u8, 2), band.nsteps); + try std.testing.expectEqualStrings("on alpha.zig", band.steps[1].rows[0].text); + // y: the place copied, the act step rolled back to the rows. + p.update(.{ .key = .{ .cp = 'y', .text = "y" } }); + try std.testing.expect(pk.spine == .rows); + // x: the current row dropped, as a refinement. + p.update(.{ .key = .{ .cp = 'l', .alt = true } }); + p.update(.{ .key = .{ .cp = 'x', .text = "x" } }); + settle(p); + try std.testing.expectEqual(@as(usize, 3), count(p, pk)); + try std.testing.expectEqual(@as(u8, 1), pk.nrefined); + // Tab Tab: two marked; Walk lands on the first and queues the second. + p.update(.{ .key = .{ .cp = Key.tab } }); + p.update(.{ .key = .{ .cp = Key.tab } }); + p.update(.{ .key = .{ .cp = 'l', .alt = true } }); + _ = frame.reset(.retain_capacity); + const marked_band = (try Band.of(p, frame.allocator(), p.panes[id].?, id)).?; + try std.testing.expectEqualStrings("on 2 marked", marked_band.steps[1].rows[0].text); + p.update(.{ .key = .{ .cp = 'w', .text = "w" } }); + try std.testing.expect(live(p) == null); + try std.testing.expectEqual(@as(i32, 1), p.panes[p.view().active].?.body.cur_row); + try std.testing.expectEqual(@as(usize, 1), pk.queue.items.len); +} + test "a picker from a reading pane unrolls in that pane, its own text set aside while it previews and back on Esc" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); defer p.deinit(); diff --git a/core/exec.zig b/core/exec.zig index 2528805f..ad1cefea 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -874,6 +874,8 @@ pub fn executeBuiltinLine(p: *Pardes, id: usize, txt: []const u8) bool { const raw = commandText(txt); if (raw.len == 0 or p.exec_depth >= max_exec_depth) return false; if (isComment(raw)) return true; + // A live picker's act and source words are its own (Pick.zig). + if (pardes.Pick.execWord(p, raw)) return true; // `+` too, so an old `Tty+fish` is renamed as `Tty fish` is. const word_end = std.mem.indexOfAny(u8, raw, " \t+") orelse raw.len; var renamed: [1024 + 16]u8 = undefined; diff --git a/core/mouse.zig b/core/mouse.zig index f97bc39b..400d020b 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -905,6 +905,18 @@ fn bandPress(p: *Pardes, button: Mouse.Button, point: BandPoint) void { if (button != config.exec_button and button != config.look_button) return; const word = (pardes.Band.wordAt(p, arena, point.id, point.line, point.col) catch return) orelse return; const kept = arena.dupe(u8, word) catch return; + // A picker's band: B2 runs the word with the picker live (an act's word + // acts, Pick.execWord); B3 on a row lands on it. + if (v.tag_state.kind == .pick) { + if (button == config.exec_button) return exec.runBuiltin(p, config.exec_cmd, v.active, "", kept); + const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return; + const ln = band.line(arena, p.settings.tab, point.line) catch return; + for (ln.parts) |part| if (point.col >= part.col and point.col < part.col + part.width) { + pardes.TagState.point(p, part.row.index); + return pardes.Pick.landHere(p); + }; + return; + } pardes.TagState.toRest(p); exec.runBuiltin(p, if (button == config.exec_button) config.exec_cmd else config.look_cmd, v.active, "", kept); } -- cgit v1.3 From 3621482c586b1d0d3601a1668a307918f1faea93 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 20:39:07 -0300 Subject: Pick: after Enter, the list word (walk UI, pick-ui SPEC.md §5.6, §6.1-§6.3 list words and n/N, item 4 of line D): Enter rolls the list into the trail of the reading pane it landed in as one word before the place, `Find pick 3/6 •2` (its word, refinements and query, where its cursor is among its rows, its marks; Trail.through, B's Trail.zig: the list a step came through), the list keeping its rows, marks, cursor and query in the session's ring; n and N in that pane walk its rows, the newest list or search word's (normal.zig, after the text's own places: a search made since is n's), in place of the current step (Trail.replaceStep: no step pushed, a file of its own a pane in its place as a step's), its word saying where it is now; a Look on the word (Trail.lookStep's list arm) unrolls the list again in that pane's tag as it was, an Exec (execStep's) runs its source again with its query from there; Resume (`SPC '`, a new builtin, docs/typ/builtins-tui.json regenerated) reopens the last picker from the pane the keyboard is in, in the tag of the pane its Enter lands in; Enter lands from the landing pane when it reads (the owner's reader or the asker itself) and from the owner otherwise; THE FAULT IT MET (B's Trail.zig, never reached before a list word existed): Trail.wordOf returned a list's, a search's or a recipe's text out of a copy of the step made by its switch, gone at the return, so a list word drew as freed bytes; the switch takes the step's own now; TEST FIRST: Pick.zig "after Enter the list is a word in the reader's trail: n and N walk its rows in place, a Look on it reopens it with its cursor and marks, Exec runs it again, Resume reopens the last" (failed on the freed bytes first); core-test 1018/1184 (166 skipped), 0 failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Pick.zig | 205 ++++++++++++++++++++++++++++++++++++++++++--- core/Trail.zig | 42 ++++++++-- core/builtins.zig | 10 +++ core/config.zig | 1 + core/normal.zig | 2 + docs/typ/builtins-tui.json | 1 + 6 files changed, 242 insertions(+), 19 deletions(-) (limited to 'core/Pick.zig') diff --git a/core/Pick.zig b/core/Pick.zig index 0f9134bb..372ff139 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -168,13 +168,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] pk.word.set(if (word.len > 0) word else words.get(source).word); pk.keys.set(words.get(source).keys); pk.dir.set(Pardes.paneDir(asker)); - pk.owner = asker.serial; pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err); - const landing = landingFor(p, from) catch |err| return p.reportError(.at(from), "pick", err); - // The keyboard stays where it was: the landing pane is the tag's host. - p.view().active = from; - pk.landing = p.panes[landing].?.serial; - pk.made = landing != from and Trail.readerOf(p, asker) != landing and !Trail.reading(p, asker); + hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "pick", err); unroll(p, pk, query); start(p, pk); filter(p, pk); @@ -206,13 +201,23 @@ fn make(p: *Pardes, source: Source) !*Pick { return pk; } -/// The pane a picker from pane `from` lands in: `from` when it reads; its -/// reader when it is held and has one; else a pane made under it as its -/// reader would be, empty until the preview fills it. +/// Picker `pk` asked from pane `from`: the pane it lands in is `from` when +/// it reads; its reader when it is held and has one; else a pane made under +/// it as its reader would be, empty until the preview fills it. The +/// keyboard stays where it was: the landing pane is the tag's host. +fn hostIn(p: *Pardes, pk: *Pick, from: usize) !void { + const asker = p.panes[from].?; + pk.owner = asker.serial; + pk.made = false; + const reader = if (Trail.reading(p, asker)) from else Trail.readerOf(p, asker); + pk.landing = p.panes[reader orelse try landingFor(p, from)].?.serial; + pk.made = reader == null; + p.view().active = from; +} + +/// A pane made under pane `from` for a picker, where its reader goes. fn landingFor(p: *Pardes, from: usize) !usize { const asker = p.panes[from].?; - if (Trail.reading(p, asker)) return from; - if (Trail.readerOf(p, asker)) |r| return r; const free = p.freeSlot() orelse return error.NoPaneSlots; const content = try p.gpa.dupe(u8, ""); errdefer p.gpa.free(content); @@ -997,9 +1002,13 @@ fn land(p: *Pardes, how: How) void { }, else => {}, }; + // A step from the pane it lands in when that reads (its owner's reader + // or itself), else from its owner, whose reader the place opens as. + const landing = if (pk.made) null else p.paneBySerial(pk.landing); TagState.toRest(p); const v = p.view(); - const from = p.paneBySerial(pk.owner) orelse v.active; + const owner = p.paneBySerial(pk.owner) orelse v.active; + const from = if (how == .walk or how == .queue) landing orelse owner else owner; v.active = from; v.jumps.force = true; for (picked, 0..) |t, k| switch (t) { @@ -1011,7 +1020,10 @@ fn land(p: *Pardes, how: How) void { _ = p.store.reopen(p, serial, from); }, .place => |at| if (k == 0 and (how == .walk or how == .queue)) { - _ = look.open(p, from, at.path, at.at, .replace); + switch (look.open(p, from, at.path, at.at, .replace)) { + .none => {}, + else => listed(p, pk), + } } else if (k == 0 and how == .column) { layout.newColumn(p, from); const c = layout.activeColumn(p) orelse continue; @@ -1029,6 +1041,113 @@ fn land(p: *Pardes, how: How) void { } } +// ---- after Enter: the list word ---- + +/// The list as its word in a trail says it (SPEC §5.6): its source, its +/// query, where its cursor is among its rows, and its marks: +/// `Find pick 3/6 •2`. +fn wordOf(p: *const Pardes, pk: *const Pick, buf: *Kind.Buf(Trail.max_text)) []const u8 { + var w: std.Io.Writer = .fixed(&buf.bytes); + w.writeAll(pk.word.slice()) catch {}; + for (pk.refined[0..pk.nrefined]) |r| w.print(" {s} |", .{r.query.slice()}) catch {}; + if (pk.query.len > 0) w.print(" {s}", .{pk.query.slice()}) catch {}; + const n = count(p, pk); + w.print(" {d}/{d}", .{ if (n == 0) 0 else pk.at + 1, n }) catch {}; + if (pk.marks.items.len > 0) w.print(" •{d}", .{pk.marks.items.len}) catch {}; + buf.len = @intCast(w.buffered().len); + return buf.slice(); +} + +/// 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; + if (!Trail.reading(p, pane)) return; + var w: Trail.Word = .{ .index = pk.id }; + _ = wordOf(p, pk, &w.text); + Trail.through(&pane.trail, .{ .list = w }); +} + +/// `n` and `N` in a reading pane whose trail's newest list or search word +/// is a list's: its next or previous row in place of the current step +/// (Trail.replaceStep), its word saying where it is now. False when there +/// is no list for them to walk (normal.zig: the search's then). +pub fn walkList(p: *Pardes, id: usize, forward: bool) bool { + const pane = p.panes[id] orelse return false; + if (!Trail.reading(p, pane)) return false; + const t = &pane.trail; + var i: usize = @min(t.cur, t.n); + while (i > 0) { + i -= 1; + switch (t.steps[i]) { + .list => break, + .search => return false, + else => {}, + } + } else return false; + const pk = byId(p, t.steps[i].list.index) orelse return false; + const n = count(p, pk); + if (n == 0) return false; + if (if (forward) pk.at + 1 >= n else pk.at == 0) { + p.setMessage(.at(id), if (forward) "n: the list's last row" else "N: the list's first row"); + return true; + } + pk.at = if (forward) pk.at + 1 else pk.at - 1; + var arena = std.heap.ArenaAllocator.init(p.gpa); + defer arena.deinit(); + const row = rowAt(p, pk, arena.allocator(), pk.at) catch return true; + const at = switch (row.target) { + .place => |x| x, + else => return true, + }; + _ = wordOf(p, pk, &t.steps[i].list.text); + _ = Trail.replaceStep(p, id, at.path, at.at) catch |err| p.reportError(.at(id), "walk", err); + 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 { + 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); + pk.landing = pane.serial; + pk.made = false; + unroll(p, pk, pk.query.slice()); + unrollRows(p, pk); +} + +/// A list unrolled again: All's places found again, the cursor where it was. +fn unrollRows(p: *Pardes, pk: *Pick) void { + const at = pk.at; + if (!fuzzy(pk) and pk.source == .all) filter(p, pk); + p.view().tag_state.rows.at = @intCast(@min(at, std.math.maxInt(u16))); +} + +/// Exec on a list word (SPEC §6.3): its source run again with its query, +/// from pane `id`. +pub fn rerun(p: *Pardes, id: usize, index: u32) void { + const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept"); + var query: Kind.Buf(256) = .{}; + query.set(pk.query.slice()); + open(p, id, pk.source, pk.word.slice(), query.slice(), pk.rows); +} + +/// Resume (`SPC '`): the last picker reopened as it was, from pane `from`, +/// in the tag of the pane its Enter lands in. +pub fn resumeFrom(p: *Pardes, from: usize) void { + var newest: ?*Pick = null; + for (p.picks) |slot| if (slot) |pk| if (newest == null or pk.id > newest.?.id) { + newest = pk; + }; + const pk = newest orelse return p.setMessage(.at(from), "Resume: no picker yet"); + TagState.toRest(p); + if (p.panes[from] == null) return; + hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "Resume", err); + unroll(p, pk, pk.query.slice()); + unrollRows(p, pk); +} + /// B3 on a picker's row (mouse.zig bandPress): Enter on it. pub fn landHere(p: *Pardes) void { const pk = live(p) orelse return; @@ -1476,6 +1595,66 @@ test "M-l unrolls the act step, which says what it acts on; Copy puts the places try std.testing.expectEqual(@as(usize, 1), pk.queue.items.len); } +test "after Enter the list is a word in the reader's trail: n and N walk its rows in place, a Look on it reopens it with its cursor and marks, Exec runs it again, Resume reopens the last" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "one\ntwo\nthree\nfour\n"); + defer p.gpa.free(a_path); + const b_path = try testFile(p, &tmp, "beta.zig", "b1\nb2\n"); + defer p.gpa.free(b_path); + _ = try p.setTestFile("held\n"); + const held = p.view().active; + Trail.keep(p.panes[held].?); + p.gpa.free(p.panes[held].?.file.?.path); + p.panes[held].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" }); + open(p, held, .list, "Refs", "", "alpha.zig:2:1 two\nbeta.zig:2:1 b2\nalpha.zig:4:1 four\n"); + const pk = live(p).?; + settle(p); + p.update(.{ .key = .{ .cp = Key.tab } }); + p.update(.{ .key = .{ .cp = Key.up } }); + p.update(.{ .key = .{ .cp = Key.enter } }); + // The reader: its owner, the list's word, the place. + const reader = Trail.readerOf(p, p.panes[held].?).?; + var t = &p.panes[reader].?.trail; + try std.testing.expectEqual(@as(u8, 3), t.n); + try std.testing.expect(t.steps[1] == .list); + try std.testing.expectEqualStrings("Refs 1/3 •1", t.steps[1].list.text.slice()); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), reader), "‹@p") != null); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), reader), " › Refs 1/3 •1 › ") != null); + // n: the next row, in place of the step (another file: a pane in its place). + p.view().active = reader; + p.update(.{ .key = .{ .cp = 'n', .text = "n" } }); + const r2 = Trail.readerOf(p, p.panes[held].?).?; + try std.testing.expectEqualStrings(b_path, p.panes[r2].?.file.?.path); + t = &p.panes[r2].?.trail; + try std.testing.expectEqual(@as(u8, 3), t.n); + try std.testing.expectEqualStrings("Refs 2/3 •1", t.steps[1].list.text.slice()); + p.update(.{ .key = .{ .cp = 'N', .text = "N", .shift = true } }); + const r3 = Trail.readerOf(p, p.panes[held].?).?; + try std.testing.expectEqualStrings(a_path, p.panes[r3].?.file.?.path); + try std.testing.expectEqual(@as(i32, 1), p.panes[r3].?.body.cur_row); + // Look on the word: the list again, in the reader's tag, as it was. + Trail.lookStep(p, r3, 1); + try std.testing.expect(live(p) == pk); + try std.testing.expectEqual(@as(?usize, r3), TagState.hostOf(p)); + try std.testing.expectEqual(@as(u16, 0), p.view().tag_state.rows.at); + try std.testing.expectEqual(@as(usize, 1), pk.marks.items.len); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Exec on it: a new picker of the same source. + Trail.execStep(p, r3, 1); + try std.testing.expect(live(p) != null and live(p) != pk); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Resume: the last one. + exec.runBuiltin(p, .Resume, held, "", null); + try std.testing.expect(live(p) != null); + p.update(.{ .key = .{ .cp = Key.escape } }); +} + test "a picker from a reading pane unrolls in that pane, its own text set aside while it previews and back on Esc" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); defer p.deinit(); diff --git a/core/Trail.zig b/core/Trail.zig index 7166d810..b88215d9 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -162,6 +162,32 @@ pub fn go(p: *Pardes, id: usize, i: u8) !usize { return show(p, id, s.place.path.slice(), .{ .line = s.place.line, .col = s.place.col }); } +/// 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 { + if (t.cur >= t.n or t.steps[t.cur] != .place) return; + if (t.n == max_steps) { + const first: usize = @intFromBool(t.steps[0] == .owner); + if (t.cur <= first) return; + std.mem.copyForwards(Step, t.steps[first .. max_steps - 1], t.steps[first + 1 ..]); + t.n -= 1; + t.cur -= 1; + } + std.mem.copyBackwards(Step, t.steps[t.cur + 1 .. t.n + 1], t.steps[t.cur..t.n]); + t.steps[t.cur] = s; + t.n += 1; + t.cur += 1; +} + +/// Reading pane `id`'s current step replaced by `path` at `at`, no step +/// pushed (a list's `n`, §5.6); its slot after it, as `step`'s. +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; + return show(p, id, path, at); +} + /// Pane `id` showing `path` at `at`, the keyboard on it: its caret moved /// in the file it shows, or a new pane on `path` in its place, its walk /// with it. A line past the new file's end is a miss that changes nothing. @@ -248,10 +274,11 @@ pub const Part = enum { back, forward }; fn wordOf(t: *const Trail, i: usize, buf: *[max_text + 16]u8) []const u8 { const s = t.steps[i]; if (s != .owner and i < t.cur and t.cur - i > shown_steps) return "·"; - return switch (s) { + // The step's own bytes, not a copy's (a copy is gone at the return). + return switch (t.steps[i]) { .owner => |serial| std.fmt.bufPrint(buf, "‹" ++ config.pane_addr ++ "{d}", .{serial}) catch unreachable, // a u32 fits .place => |at| std.fmt.bufPrint(buf, "{s}:{d}", .{ std.Io.Dir.path.basename(at.path.slice()), at.line }) catch unreachable, // a basename and a u32 fit - .list, .search, .recipe => |w| w.text.slice(), + .list, .search, .recipe => |*w| w.text.slice(), }; } @@ -302,8 +329,9 @@ pub fn stepAt(t: *const Trail, part: Part, off: usize) ?u8 { } /// Look on step `i` of pane `id`'s trail (§6.3): a place is gone back or -/// forward to, the owner focused; a list, a search or a recipe is the -/// pickers' and the prompts' to take (not yet: said). +/// forward to, the owner focused, a list unrolled again as it was +/// (Pick.reopen); a search or a recipe is the prompts' to take (not yet: +/// said). pub fn lookStep(p: *Pardes, id: usize, i: u8) void { const pane = p.panes[id] orelse return; switch (pane.trail.steps[i]) { @@ -311,7 +339,8 @@ 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, .search, .recipe => p.setMessage(.at(id), "walk: a list, a search or a recipe is not walked yet"), + .list => |w| pardes.Pick.reopen(p, id, w.index), + .search, .recipe => p.setMessage(.at(id), "walk: a search or a recipe is not walked yet"), } } @@ -321,7 +350,8 @@ pub fn execStep(p: *Pardes, id: usize, i: u8) void { const pane = p.panes[id] orelse return; switch (pane.trail.steps[i]) { .place, .owner => lookStep(p, id, i), - .list, .search, .recipe => p.setMessage(.at(id), "walk: a list, a search or a recipe is not run again yet"), + .list => |w| pardes.Pick.rerun(p, id, w.index), + .search, .recipe => p.setMessage(.at(id), "walk: a search or a recipe is not run again yet"), } } diff --git a/core/builtins.zig b/core/builtins.zig index 12ab9da5..589915c2 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -1998,6 +1998,16 @@ pub const Forward = struct { } }; +/// Reopen the last picker as it was: its rows, marks, cursor and query. +/// +/// In the tag of the pane its Enter lands in from this one: this pane if it +/// reads, else its reader. `SPC '`. +pub const Resume = struct { + pub fn run(c: Ctx) void { + pardes.Pick.resumeFrom(c.p, c.id); + } +}; + /// Keep this pane: a reading pane, which a jump steps, is held from now on. /// /// Its walk leaves its tag (its places, its owner): the next jump from its diff --git a/core/config.zig b/core/config.zig index 6adebe1b..c924796a 100644 --- a/core/config.zig +++ b/core/config.zig @@ -145,6 +145,7 @@ pub const leader_path = paths: { .Back = "jo", .Forward = "ji", .Keep = "jk", + .Resume = "'", .Last = "jj", .Jumplist = "jl", .History = "fh", diff --git a/core/normal.zig b/core/normal.zig index 1f7ce1a7..2ec8a4da 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -1379,6 +1379,8 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! return look.lookWalk(p, if (a.role == .search_next) 1 else -1, false) else if (t.what == .body and pane.file != null and pane.places.answersN(p, pane)) return pane.places.step(p, pane, a.role == .search_next, a.count, t.select) + else if (t.what == .body and panes.Pick.walkList(p, v.active, a.role == .search_next)) + return else return searchStep(p.editor(), t, text, a.role == .search_next, a.count), .goto_word => return startJump(p, pane, t), diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index 4985fa42..43fdeb03 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -85,6 +85,7 @@ {"name": "Rename", "leader": "SPC l r", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Rename the symbol under the cursor to its argument, wherever the language server finds it.", "text": "Rename the symbol under the cursor to its argument, wherever the language server finds it.\nBare, it asks for the new name. Within this file it is done at once, saying how many places changed; one that reaches other files changes nothing and lists its edits in a +Search to look over."}, {"name": "Repl", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Bind this terminal as a language's REPL: an exec on that language's files is typed into it.", "text": "Bind this terminal as a language's REPL: an exec on that language's files is typed into it.\n`Repl python` binds it (the language named as a code fence names it: `py`, `Python`, `sh`); `Repl -` unbinds it; bare, it says what it is bound as. An exec made on the body of a file in that language (a middle click, the execute key, a single word like `ls` as much as a selection), and one made on this terminal's own body, is typed into it (bracketed paste if its program asked for that, else line by line, then Enter) instead of run. With several bound for a language, the exec asks which.\nStill commands, whatever is bound: a word in a tag, `Exec `, a ctl line, and a command word @`cmd` in the text, looked at or clicked."}, {"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump.", "text": "Replace every pane with those of a dump.\n`Restore