From abe3817e8dd0af41e6b5786bdbeb631219b58c23 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 20:33:01 -0300 Subject: Prompt: a body's text prompts ask in its tag's head (walk UI, pick-ui SPEC.md §7.1, §7.2, item 1 of line E): `s S K A-K | A-| ! A-! $` from a body are a typing state of the view's tag (TagState.Kind.prompt, its state Prompt.zig, its field A's Field), drawn after the prefix in place of the tag's own text (R1): box `^`, the prompt's key cell, the field, the plain word it stands for (`= Exec Edit x/self/`, `Edit g/re/`, `Edit |tr a-z A-Z`, `Edit >cmd`; none for `! A-! $`), its count (`2 selections in 3 lines`, `keeps 1 of 2`, `0` for no match, the selections it began with back), the hints; the live machinery as it was (normal.applySelRegex, now returning what it found; the pipe off the loop, Pipe.submit split from the notice band's submitPipe); a pattern that is no regex changes nothing, the last result drawn dimmed (body_layer) and the reason at the count's place in the error ink (TagState.Style.err, regexp's message); Up/Down recall the history inline, Ctrl-r unrolls it as a band step filtered by the field (three session histories, Pardes.prompt_history: search and select's, the pipes', the command line's, 16 lines each, in the digest and the dump); Esc and Backspace on an empty field put the body back; Enter keeps the line in its history and the pattern in `/`, the command in `|`; a paste goes into the field; a prompt for a tag's or a header's text, Save's path, a terminal's `/` still ask on the notice band; wire 37; TEST FIRST: Prompt.zig "s asks in the tag's head ..." and "Enter keeps what s found ... a pipe from the body asks in the tag and runs off the loop"; Pipe.zig's and panes.zig's prompt tests and test/behaviour/keys.zig's two read the head; goldens pipe, selregex, msg (the prompt in the tag head, no chip); core-test 1014/1180 (166 skipped), shell-test 1227/1230, pane-test 182/184 (the 1 failure A's: `SPC h ?` is Help in the tag now), behaviour-test 274/277 (the 3 failures A's: window mode's head, a struck leader key), process-test the 6 of A's report plus none of mine, term-test 17/17, kitty-test 45/45 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Band.zig | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'core/Band.zig') diff --git a/core/Band.zig b/core/Band.zig index 079a1bcc..7f9cfc7b 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -27,6 +27,7 @@ const panes = @import("panes.zig"); const builtins = @import("builtins.zig"); const TagState = @import("TagState.zig"); const Names = @import("Names.zig"); +const Prompt = @import("Prompt.zig"); const Pardes = pardes.Pardes; const Pane = pardes.Pane; const File = panes.File; @@ -89,6 +90,7 @@ pub fn takes(p: *Pardes, id: usize) u16 { .rest => {}, .help => return @max(doc_rows, @max(1, @min(Cursor.shown, s.nhits))), .describe => return 0, + .prompt => return Prompt.takes(p), } if (!s.unrolled) return 0; const cur = TagState.current(p, v) orelse return 0; @@ -117,6 +119,12 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band { return band; }, .describe => return null, + .prompt => { + var steps: [max_steps]Step = undefined; + for (try Prompt.steps(p, arena, &steps)) |step| band.add(step); + try band.place(p, arena, pane, id); + return band; + }, } const cur = TagState.current(p, v).?; // The level, its cursor on the child it names, else the leaf its group -- cgit v1.3 From b44a129a8854483dbe45ce2bcfa09f33ccbd6e8c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 22:16:38 -0300 Subject: registers: `"` shows the registers rolled in the tag, each its key and the first line of its value (`" ▸ " self.dirty = true; a const best = rank(q, nam… / — … % core/x.zig . o # 1 _ —`), `↓` unrolls them a row each (key, what it is, first line) beside the cursor's value in full, and choosing one (its key, or Enter) goes down to its verbs rolled (`" a ▸ p after P before R replace y into`), Backspace back up, Esc to rest (pick-ui SPEC §9, walk UI line F item 1): the level is built from the registers (and the four computed from the pane with the keyboard) when it is read, as the addon words join SPC's (bindings.registerLevel, registerValue: the first value only, a first line cut at 24 columns and never scanned past 96 bytes, the value step reading only the lines the band shows); a register named (`t.normal.register`, the parser's) is the root `"` with that key as its path (TagState.current), its verbs a node of normal mode's paste, yank and replace roles (bindings.register_verbs, a group slot of its own: TagState.used one longer, the dump with it); keys.prefixKey reads the level at the current path, Esc there goes to rest (normal mode's Esc would have named the register ESC, then left the pane), Backspace from the verbs goes back to `"`; TEST: bindings.zig "\" shows the registers rolled ..." (the level, the band's rows and value, Enter, Backspace, `a p` pasting, Esc); core-test 1024/1191 (167 skipped), 0 failed, load 5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Band.zig | 66 ++++++++++++++++++++- core/TagState.zig | 11 +++- core/bindings.zig | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++- core/keys.zig | 28 +++++++-- 4 files changed, 266 insertions(+), 11 deletions(-) (limited to 'core/Band.zig') diff --git a/core/Band.zig b/core/Band.zig index 3c800bf0..13c4b9c0 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -105,6 +105,8 @@ pub fn takes(p: *Pardes, id: usize) u16 { const cur = TagState.current(p, v) orelse return 0; var children: [bindings.max_children]bindings.Child = undefined; const n: u16 = @intCast(bindings.level(p, cur.root, cur.path, &children).len); + // The registers, one column of eleven at most (registerSteps). + if (cur.root == .register and cur.path.len == 0) return @max(doc_rows, @min(Cursor.shown, n)); return @max(doc_rows, levelRows(n)); } @@ -151,6 +153,11 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band { }, } const cur = TagState.current(p, v).?; + if (cur.root == .register) { + try band.registerSteps(p, arena, pane, cur.path); + try band.place(p, arena, pane, id); + return band; + } // The level, its cursor on the child it names, else the leaf its group // ran last, else the first; and that child's doc beside it. const node = bindings.nodeAt(cur.root, cur.path); @@ -196,6 +203,63 @@ fn helpSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, s: *const TagSta band.add(try docStep(p, arena, at.root, at.path[0 .. at.path.len - 1], at.child)); } +/// `"` unrolled (SPEC §9): the registers, a row each (its key, what it +/// is, its first line) around the cursor, or under `"a` its verbs; beside +/// them the value of the one on the cursor (or named) in full, as many of +/// its lines as the band has rows, only those read. +fn registerSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *const Pane, path: []const u8) !void { + const s = &p.view().tag_state; + var children: [bindings.max_children]bindings.Child = undefined; + const level = bindings.level(p, .register, path, &children); + const node = bindings.nodeAt(.register, path); + const used = if (node) |n| s.used[n.group] else 0; + var at: usize = 0; + for (level, 0..) |c, i| if (c.key == (if (s.hi != 0) s.hi else used)) { + at = i; + }; + if (path.len > 0) band.add(try levelStep(arena, pane, level, at, used)) else { + const w = (Cursor{ .at = @intCast(at) }).window(@intCast(level.len)); + const rows = try arena.alloc(Row, w.hi - w.lo); + for (rows, w.lo..) |*row, i| { + const c = level[i]; + const name = for (bindings.register_names) |r| { + if (r.key == c.key) break r.name; + } else "named"; + row.* = .{ + .text = try std.fmt.allocPrint(arena, "{s} {s: <17} {s}{s}", .{ bindings.keyName(c.key), name, c.label, if (c.more) "…" else "" }), + .on = i == at, + .key = 1, + .under = c.key == used, + .index = @intCast(i), + }; + } + band.add(.{ .rows = rows }); + } + const key = if (path.len > 0) path[0] else level[at].key; + const name = for (bindings.register_names) |r| { + if (r.key == key) break r.name; + } else "named"; + var rows: std.ArrayList(Row) = .empty; + try rows.append(arena, .{ .text = try std.fmt.allocPrint(arena, "\"{s} · {s}", .{ bindings.keyName(key), name }), .key = 2 }); + const value = bindings.registerValue(p, key); + if (value.len == 0) try rows.append(arena, .{ .text = "(empty)", .dim = true }); + // A line is cut at what the band could show of it: a long one is + // never scanned past that. + const most = @as(usize, band.columns) * band.height; + var rest = value; + while (rest.len > 0 and rows.items.len + 1 < band.height) { + const look = rest[0..@min(rest.len, most)]; + const end = std.mem.indexOfScalar(u8, look, '\n') orelse { + try rows.append(arena, .{ .text = rest[0..if (look.len < rest.len) modal.graphemeStart(rest, look.len) else look.len] }); + break; + }; + try rows.append(arena, .{ .text = look[0..end] }); + rest = rest[end + 1 ..]; + } + if (path.len == 0) try rows.append(arena, .{ .text = "next p after P before R replace y into", .dim = true }); + band.add(.{ .rows = rows.items, .doc = true }); +} + /// A list's cursor and the rows of it a band shows: eleven at most, around /// the cursor (SPEC §3.6, the prototype's `H.window`). Each view's (a /// tag state's field): Help's rows, a picker's, a prompt's history. @@ -245,7 +309,7 @@ pub fn levelStep(arena: std.mem.Allocator, pane: *const Pane, level: []const bin for (level, rows, 0..) |c, *row, i| { const key = bindings.keyName(c.key); row.* = .{ - .text = try std.fmt.allocPrint(arena, "{s} {s}{s}", .{ key, c.label, if (c.group) "…" else "" }), + .text = try std.fmt.allocPrint(arena, "{s} {s}{s}", .{ key, c.label, if (c.group or c.more) "…" else "" }), .on = i == at, .key = @intCast(key.len), .dim = bindings.dimmed(pane, c), diff --git a/core/TagState.zig b/core/TagState.zig index 5a30f182..95df8937 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -152,7 +152,11 @@ pub fn current(p: *const Pardes, v: *const View) ?Current { if (v != p.view() or v.header != null) return null; const pane = p.panes[v.active] orelse return null; const t = if (pane.focus == .tag) &pane.tag else &pane.body; - const prefix = t.normal.prefix orelse return null; + const prefix = t.normal.prefix orelse { + // `"a`: the register named, its verbs next (SPEC §9). + const r = t.normal.register; + return if (r > ' ' and r <= '~') .{ .root = .register, .path = bindings.keyName(@intCast(r)) } else null; + }; const root: Root = switch (prefix) { .goto_prefix => .goto, .view_prefix => if (t.normal.sticky) .view_sticky else .view, @@ -188,7 +192,8 @@ pub fn hostOf(p: *const Pardes) ?usize { fn textPrefix(p: *const Pardes, v: *const View) bool { const pane = p.panes[v.active] orelse return false; - return pane.body.normal.prefix != null or pane.tag.normal.prefix != null; + return pane.body.normal.prefix != null or pane.tag.normal.prefix != null or + pane.body.normal.register != 0 or pane.tag.normal.register != 0; } /// After a key (keys.handleKey): a root newly current starts its delay; one @@ -515,7 +520,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { try b.styled(bindings.keyName(c.key), .key); try b.put(" "); try b.put(c.label); - if (c.group) try b.put("…"); + if (c.group or c.more) try b.put("…"); const hi: u32 = @intCast(b.text.items.len); if (bindings.dimmed(pane, c)) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .dim }); if (c.key == used) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .under }); diff --git a/core/bindings.zig b/core/bindings.zig index b2d84a7c..f7be1a43 100644 --- a/core/bindings.zig +++ b/core/bindings.zig @@ -15,6 +15,8 @@ const Pardes = pardes.Pardes; const Pane = pardes.Pane; const Key = pardes.Key; const Role = modal.Normal.Role; +const edit = @import("edit.zig"); +const File = @import("File.zig"); /// The keys a sequence starts with. `register` (`"`) is drawn the same way /// but its rows are the registers' contents, not a tree. @@ -87,8 +89,9 @@ pub const groups = groups: { }; break :groups paths; }; -/// SPC's groups, then one for each other root. -pub const ngroups = groups.len + std.enums.values(Root).len - 1; +/// SPC's groups, then one for each other root, then the verbs a register +/// takes (`"a ▸`). +pub const ngroups = groups.len + std.enums.values(Root).len; fn rootGroup(comptime r: Root) u8 { return @intCast(groups.len + @intFromEnum(r) - 1); @@ -233,6 +236,15 @@ const view_sticky_tree: Node = .{ .key = config.view_prefix_sticky, .label = "vi const prev_tree: Node = .{ .key = config.prev_prefix, .label = "previous", .children = roleLevel(.goto_paragraph, .goto_xml_element, &.{}), .group = rootGroup(.prev) }; const next_tree: Node = .{ .key = config.next_prefix, .label = "next", .children = roleLevel(.goto_paragraph, .goto_xml_element, &.{}), .group = rootGroup(.next) }; const register_tree: Node = .{ .key = config.register_prefix, .label = "registers", .group = rootGroup(.register) }; +/// What the register `"` named does next (SPEC §9: `"a ▸ p after P before +/// y into R replace`): normal mode's paste, yank and replace, which read +/// the register the parser holds. +const register_verbs: Node = .{ .key = 0, .label = "register", .group = ngroups - 1, .children = sorted(&.{ + .{ .key = roleKey(.paste_after).?, .label = "after", .leaf = .{ .role = .paste_after } }, + .{ .key = roleKey(.paste_before).?, .label = "before", .leaf = .{ .role = .paste_before } }, + .{ .key = roleKey(.yank).?, .label = "into", .leaf = .{ .role = .yank } }, + .{ .key = roleKey(.replace_with_yank).?, .label = "replace", .leaf = .{ .role = .replace_with_yank } }, +}) }; /// pardes's window mode (layout.windowKey): its moves, Collapse and Del; /// a letter picks the pane its box shows. const window_tree: Node = .{ .key = 'w', .label = "window", .group = rootGroup(.window), .children = window: { @@ -248,7 +260,13 @@ const window_tree: Node = .{ .key = 'w', .label = "window", .group = rootGroup(. /// The node `path` reaches under `root`, or null. pub fn nodeAt(root: Root, path: []const u8) ?*const Node { var n = info.get(root).node; - for (path) |k| n = for (n.children) |*c| { + var keys = path; + // A register's name is any key: under each, its verbs. + if (root == .register and path.len > 0) { + n = ®ister_verbs; + keys = path[1..]; + } + for (keys) |k| n = for (n.children) |*c| { if (c.key == k) break c; } else return null; return n; @@ -263,6 +281,8 @@ pub const Child = struct { word: ?*const pardes.Kind.Word = null, group: bool = false, lsp: bool = false, + /// Its label is cut (a register's first line): `…` after it. + more: bool = false, }; /// The most children a level shows: SPC's top has 17, and an addon's /// words (Kind.Registry's 64) may each start a key of their own. @@ -273,6 +293,7 @@ pub const max_children = 96; /// addons' leader words joined in (SPC alone). Bounded by the level and the /// registry's 64 words. pub fn level(p: *const Pardes, root: Root, path: []const u8, out: *[max_children]Child) []Child { + if (root == .register and path.len == 0) return registerLevel(p, out); var n: usize = 0; if (nodeAt(root, path)) |node| for (node.children) |*c| { if (c.leaf) |leaf| if (leaf == .builtin and !builtins.registry.here(p, leaf.builtin)) continue; @@ -300,6 +321,87 @@ pub fn level(p: *const Pardes, root: Root, path: []const u8, out: *[max_children return shown; } +/// The registers `"` shows (SPEC §9), in its order, and what each is: the +/// default first, the ones a name was given (`"ay`) after it, by name, +/// then these, the last four computed from the pane with the keyboard. +pub const register_names = [_]struct { key: u8, name: []const u8 }{ + .{ .key = '"', .name = "yank" }, + .{ .key = '/', .name = "last search" }, + .{ .key = ':', .name = "last command" }, + .{ .key = '|', .name = "last pipe" }, + .{ .key = '+', .name = "system clipboard" }, + .{ .key = '@', .name = "last macro" }, + .{ .key = '%', .name = "this file's name" }, + .{ .key = '.', .name = "the selections" }, + .{ .key = '#', .name = "selection numbers" }, + .{ .key = '_', .name = "black hole" }, +}; + +/// The display columns of a register's first line which-key shows; the +/// rest is `…`. +pub const register_cut = 24; + +/// `"`'s level: a child a register, its label the first line of its value +/// (`—` when empty), cut. Read when the level is (a key, a frame), never +/// kept: the first `register_cut` columns of each, the named ones bounded +/// by the level's room. +fn registerLevel(p: *const Pardes, out: *[max_children]Child) []Child { + var n: usize = 1; + for (p.registers.list.items) |*reg| { + if (reg.name <= ' ' or reg.name > '~' or n == out.len - (register_names.len - 1)) continue; + const k: u8 = @intCast(reg.name); + for (register_names) |r| { + if (r.key == k) break; + } else { + var j = n; + while (j > 1 and out[j - 1].key > k) : (j -= 1) out[j] = out[j - 1]; + out[j] = .{ .key = k, .label = "" }; + n += 1; + } + } + out[0] = .{ .key = '"', .label = "" }; + for (register_names[1..]) |r| { + out[n] = .{ .key = r.key, .label = "" }; + n += 1; + } + for (out[0..n]) |*c| { + const value = registerValue(p, c.key); + const bound = if (value.len > 4 * register_cut) modal.graphemeStart(value, 4 * register_cut) else value.len; + const line = value[0 .. std.mem.indexOfScalar(u8, value[0..bound], '\n') orelse bound]; + const cut = File.byteAtDisplay(p.settings.tab, line, register_cut); + c.label = if (value.len == 0) "—" else line[0..cut]; + c.more = cut < value.len; + } + return out[0..n]; +} + +/// Register `key`'s value as a paste of the pane with the keyboard reads +/// its first range's (edit.registerValue): a stored one's first value; `%` +/// the file's name, `.` the primary selection's text, `#` its number, `_` +/// nothing. Borrowed from the register or the pane, for the frame. +pub fn registerValue(p: *const Pardes, key: u8) []const u8 { + const pane = p.panes[p.view().active] orelse return ""; + switch (key) { + '_' => return "", + '#' => return "1", + '%' => return if (pane.file) |*f| f.path else "", + '.' => { + const f = if (pane.file) |*f| f else return ""; + const t = &pane.body; + const b = edit.cellBounds(.{ .row = t.cur_row, .col = t.cur_col, .arow = if (t.vsel.active) t.vsel.row else t.cur_row, .acol = if (t.vsel.active) t.vsel.col else t.cur_col }); + const first = File.sourceLine(pane, b.lo_row); + const last = File.sourceLine(pane, b.hi_row); + if (f.content.len == 0) return ""; + const lo = @min(f.content.len, first.ptr - f.content.ptr + @as(usize, @intCast(@max(0, b.lo_col)))); + const hi = @min(f.content.len, last.ptr - f.content.ptr + @as(usize, @intCast(@max(0, b.hi_col)))); + return f.content[lo..modal.nextGrapheme(f.content, @max(lo, hi))]; + }, + else => for (p.registers.list.items) |*reg| { + if (reg.name == key) return if (reg.values.len == 0) "" else reg.values[0]; + } else return "", + } +} + /// A key as a cell shows it: `SPC` for the space. pub fn keyName(key: u8) []const u8 { return if (key == ' ') "SPC" else @as(*const [1]u8, &printable[key - 0x20]); @@ -450,3 +552,67 @@ test "Help's rows: every leaf of every root, spelled as its chord, its word and try std.testing.expectEqual(@as(usize, 4), found); for (flat) |f| try std.testing.expectEqual(f.row.len, f.lower.len); } + +test "\" shows the registers rolled, each its first line; Down unrolls them beside the cursor's value; a register's key goes down to its verbs, Backspace back up, p pastes it" { + const tagline = @import("tagline.zig"); + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile("one\ntwo\n"); + try p.registers.put(p.gpa, 'a', "const best = rank(q, name) orelse continue;\nreturn best;", 0, 1, true); + try p.registers.put(p.gpa, '"', "self.dirty = true;", 0, 1, true); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + p.clock.now_ns = 5 * std.time.ns_per_s; + p.clock.stepped_ns = p.clock.now_ns; + p.sync(); + // Its key cell at once, the level 300 ms on. + p.update(.{ .key = .{ .cp = '"' } }); + try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, a, pane), " \" …")); + p.advance(p.clock.now_ns); + try std.testing.expectEqual(p.clock.now_ns + 300 * std.time.ns_per_ms, p.view().tag_state.due_ns); + p.clock.now_ns = p.view().tag_state.due_ns; + const rolled = try tagline.tagText(p, a, pane); + try std.testing.expect(std.mem.indexOf(u8, rolled, " \" ▸ \" self.dirty = true; a const best = rank(q, nam… / —") != null); + try std.testing.expect(std.mem.indexOf(u8, rolled, "% /test.txt . o # 1 _ —") != null); + // Down unrolls: a row each, the cursor on the default, its value + // beside them. + p.update(.{ .key = .{ .cp = Key.down } }); + try std.testing.expect(p.view().tag_state.unrolled); + try std.testing.expect(pane.band_rows >= 4); + _ = try p.render(a); + const layer = &p.surface.tag_layers[pardes.BAND_LAYER_BASE + p.view().active]; + var band: std.ArrayList(u8) = .empty; + for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| try band.appendSlice(a, cell.grapheme()); + try std.testing.expect(std.mem.indexOf(u8, band.items, "▶ \" yank self.dirty = true;") != null); + try std.testing.expect(std.mem.indexOf(u8, band.items, "\"\" · yank") != null); + // The next row's value in full, every line of it. + p.update(.{ .key = .{ .cp = Key.down } }); + _ = frame.reset(.retain_capacity); + _ = try p.render(a); + band = .empty; + for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| try band.appendSlice(a, cell.grapheme()); + try std.testing.expect(std.mem.indexOf(u8, band.items, "const best = rank(q, name) orelse continue;") != null); + try std.testing.expect(std.mem.indexOf(u8, band.items, "return best;") != null); + // Enter chooses it: its verbs, rolled. + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" a ▸ p after P before R replace y into") != null); + try std.testing.expect(!p.view().tag_state.unrolled); + // Backspace: the registers again; a register's own key goes down too. + p.update(.{ .key = .{ .cp = Key.backspace } }); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" ▸ \" self.dirty") != null); + p.update(.{ .key = .{ .cp = 'a' } }); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" a ▸ p after") != null); + // p pastes it after the selection, and the tag is at rest. + p.update(.{ .key = .{ .cp = 'p' } }); + try std.testing.expect(std.mem.indexOf(u8, pane.file.?.content, "const best = rank(q, name) orelse continue;") != null); + try std.testing.expect(p.view().tag_state.root == null); + try std.testing.expect(@import("TagState.zig").hostOf(p) == null); + // Esc from the registers: rest, the keyboard where it was. + const id = p.view().active; + p.update(.{ .key = .{ .cp = '"' } }); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(p.view().tag_state.root == null); + try std.testing.expectEqual(id, p.view().active); + try std.testing.expectEqual(@as(u21, 0), pane.body.normal.register); +} diff --git a/core/keys.zig b/core/keys.zig index 04a3cc35..78f45820 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -376,7 +376,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { return; } if (header == null) if (TagState.current(p, p.view())) |cur| if (cur.root != .leader and cur.root != .window) { - if (prefixKey(p, t, cur.root, key)) return; + if (prefixKey(p, t, cur, key)) return; }; if (t == &pane.body and pane.jump.items.len > 0) return normal.jumpKey(p, pane, t, key); // A query pane's line 1 answers Enter, Esc and the stepping keys @@ -679,15 +679,27 @@ fn levelKey(p: *Pardes, root: bindings.Root, path: []const u8, key: Key) LevelSt /// A key while a helix prefix waits in text `t` (g m z Z [ ]): which-key's /// own, else the prefix's, the leaf it runs remembered. True when taken here. -fn prefixKey(p: *Pardes, t: *Text, root: bindings.Root, key: Key) bool { +fn prefixKey(p: *Pardes, t: *Text, cur: TagState.Current, key: Key) bool { + const root = cur.root; if (root != .register and key.cp == config.leader_help and !key.ctrl and !key.alt) { TagState.openHelp(p, root, ""); return true; } - switch (levelKey(p, root, "", key)) { + // `"` and a register's verbs: Esc goes to rest (normal mode's would + // name the register, or leave the pane). + if (root == .register and hit(key, config.escape)) { + t.normal.clear(); + return true; + } + switch (levelKey(p, root, cur.path, key)) { .taken => return true, .up => { t.normal = .{}; + // A register's verbs go back up to the registers (SPEC §9). + if (root == .register and cur.path.len > 0) { + t.normal.prefix = .register_prefix; + p.view().tag_state.hi = 0; + } return true; }, .take => |c| { @@ -697,7 +709,15 @@ fn prefixKey(p: *Pardes, t: *Text, root: bindings.Root, key: Key) bool { .pass => { if (!key.ctrl and !key.alt and key.cp >= 0x20 and key.cp < 0x7f) { const k: u8 = @intCast(key.cp); - if (bindings.nodeAt(root, &.{k}) != null) TagState.ran(p.view(), root, "", k); + var buf: [2]u8 = .{ 0, k }; + if (cur.path.len > 0) buf[0] = cur.path[0]; + const here = if (cur.path.len > 0) buf[0..2] else buf[1..2]; + if (bindings.nodeAt(root, here) != null) TagState.ran(p.view(), root, cur.path, k); + // A register named: its verbs, rolled, the cursor afresh. + if (root == .register) { + p.view().tag_state.hi = 0; + p.view().tag_state.unrolled = false; + } } return false; }, -- cgit v1.3 From 5d091b37b4641c274900d4d02b7f1d61b5a9301f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 22:51:55 -0300 Subject: lsp: a hover (SPC l k) and a rename (SPC l r) asked from the keyboard show in the edited pane's own body: the hover as ghost lines under the line it was asked at, no +Hover pane, Esc taking them away; Rename typed in that pane's tag (` Rename best → bester▌`, the old name struck), each whole-word place of the old name in the rows shown drawn struck with the new name after it as it is typed, Enter asking the server for it (its edits applied as before), Esc asking nothing (pick-ui SPEC §3.5, §14.1, R3, walk UI line F item 3, its hover and rename; code actions NOT done: the protocol client sends an action's title alone, no edit to preview or apply): Ask.hover (its pane, line, revision and first 1,024 bytes, in the dump; an edit of the text stops it showing), body_layer.hoverGhosts and renameGhosts (drawn after the rows as the message ghosts are, the rows below pushed down or a row's cells pushed right, never written, the rows shown alone), TagState.Kind.rename (its head; no band), Ask.openRename and renameKey, the name under the caret Ask.renamedWord (the preview is pardes's own whole-word match in view, the edit the server's on Enter); under `Jumps new-pane` or from a 9P script, +Hover and the rename prompt as before; TESTS: Ask.zig "a hover asked from the keyboard is ghost lines ..." and "SPC l r types the new name in the pane's own tag ..."; core-test 1029/1196 (167 skipped), 0 failed, load 8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Band.zig | 2 + core/TagState.zig | 17 +++++- core/body_layer.zig | 90 +++++++++++++++++++++++++++++++ core/builtins.zig | 3 ++ core/keys.zig | 7 +++ core/lsp/Ask.zig | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 267 insertions(+), 1 deletion(-) (limited to 'core/Band.zig') diff --git a/core/Band.zig b/core/Band.zig index 13c4b9c0..63407626 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -100,6 +100,7 @@ pub fn takes(p: *Pardes, id: usize) u16 { return @max(doc_rows, levelRows(@intCast(bindings.level(p, s.scope_root.?, s.scope[0 .. s.scope_n - 1], &children).len))); }, .pick => return @import("Pick.zig").bandRows(p), + .rename => return 0, } if (!s.unrolled) return 0; const cur = TagState.current(p, v) orelse return 0; @@ -151,6 +152,7 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band { try band.place(p, arena, pane, id); return band; }, + .rename => return null, } const cur = TagState.current(p, v).?; if (cur.root == .register) { diff --git a/core/TagState.zig b/core/TagState.zig index 95df8937..1d6abace 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -24,12 +24,13 @@ const Root = bindings.Root; const Field = @import("Field.zig"); const Band = @import("Band.zig"); const Names = @import("Names.zig"); +const Ask = @import("lsp/Ask.zig"); /// The tag's states besides a root's level (which `kind` rest with a root /// current is): `help`, a field over every leaf (SPEC §4.5); `describe`, /// a sequence replayed in the tree (item 5); `pick`, a picker (Pick.zig, /// SPEC §5). -pub const Kind = enum(u8) { rest, help, describe, pick }; +pub const Kind = enum(u8) { rest, help, describe, pick, rename }; pub const replica = .{ .len = .{ .{ "scope", "scope_n" }, .{ "hits", "nhits" } } }; @@ -483,6 +484,20 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { return b.done(); }, .pick => return @import("Pick.zig").head(p, arena, pane), + // `Rename`, the name under the caret struck, the new one typed: + // ` Rename best → top▌ ⏎ rename · esc` (SPEC §3.5). + .rename => { + try b.put(" Rename "); + try b.styled(Ask.renamedWord(pane) orelse "", .strike); + try b.put(" → "); + var h = b.done(); + h.caret = @intCast(b.text.items.len + s.field.caret); + try b.put(s.field.text()); + try b.put(" ⏎ rename · esc"); + h.text = b.text.items; + h.spans = b.spans.items; + return h; + }, } const cur = current(p, v) orelse return null; try b.put(" "); diff --git a/core/body_layer.zig b/core/body_layer.zig index 13fc7a85..13c24f97 100644 --- a/core/body_layer.zig +++ b/core/body_layer.zig @@ -472,6 +472,8 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane } if (pane.file != null) paintTargets(p, s, arena, pane, r, tx, tw, body_y, body_h); + if (p.lsp_ask.hover != null) hoverGhosts(p, s, pane, tx, tw, body_y, body_h); + if (p.view().tag_state.kind == .rename) renameGhosts(p, s, pane, tx, tw, body_y, body_h); // `gw`'s labels, two letters over the start of each word if (pane.jump.items.len > 0) labels: { @@ -632,6 +634,94 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, } } +/// A hover's answer as ghost lines under the line it was asked at (SPEC +/// §3.5, R3): the rows below move down by its lines (those past the body's +/// foot not shown meanwhile), the buffer untouched. Bounded by the rows +/// shown and the hover's `Ask.hover_max` bytes. +fn hoverGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u16, body_h: u16) void { + const h = &p.lsp_ask.hover.?; + if (h.serial != pane.serial) return; + const f = if (pane.file) |*file| file else return; + if (f.revision != h.revision) return; + const tab = p.settings.tab; + // The last row the line is shown on. + var under: ?u16 = null; + var row: u16 = pane.context_rows; + while (row < body_h) : (row += 1) { + if (pane.wrapAt(tab, row).line == h.row) under = row else if (under != null) break; + } + const at = under orelse return; + const text = std.mem.trimEnd(u8, h.text.slice(), "\n"); + const k: u16 = @intCast(@min(std.mem.count(u8, text, "\n") + 1, body_h - at - 1)); + if (k == 0) return; + var dst: u16 = body_h - 1; + while (dst >= at + 1 + k) : (dst -= 1) { + const to = @as(usize, body_y + dst) * s.cols + tx; + const from = @as(usize, body_y + dst - k) * s.cols + tx; + @memcpy(s.cells[to..][0..tw], s.cells[from..][0..tw]); + } + const th = p.theme(); + const style: CellStyle = .{ .fg = .{ .rgb = th.tag_fg }, .bg = .{ .rgb = th.tag_bg } }; + const gutter: u16 = File.gutterWidth(pane); + var lines = std.mem.splitScalar(u8, text, '\n'); + for (0..k) |i| { + const y = body_y + at + 1 + @as(u16, @intCast(i)); + s.fill(tx, y, tw, 1, .{ .bg = .{ .rgb = th.tag_bg } }); + if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, lines.next() orelse "", style); + } +} + +/// A Rename typed in this body's tag, shown in its rows (SPEC §3.5, R3): +/// each whole-word place of the name under the caret in the rows shown +/// struck, the name typed after it, the rest of its row pushed right. +/// Never written; bounded by the rows shown. +fn renameGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u16, body_h: u16) void { + const host = TagState.hostOf(p) orelse return; + if (p.panes[host] != pane or pane.file == null) return; + const old = @import("lsp/Ask.zig").renamedWord(pane) orelse return; + const new = p.view().tag_state.field.text(); + const tab = p.settings.tab; + const chrome = p.chromeTheme(); + const th = p.theme(); + const added: CellStyle = .{ .fg = .{ .rgb = chrome.diagnostic_hint }, .bg = if (th.bg) |c| .{ .rgb = c } else .default, .bold = true }; + const wide: u16 = @intCast(@min(File.displayWidth(tab, new), tw)); + const gutter: i32 = File.gutterWidth(pane); + var row: u16 = pane.context_rows; + while (row < body_h) : (row += 1) { + const w = pane.wrapAt(tab, row); + if (w.line < 0) continue; + const line = File.sourceLine(pane, w.line); + const from: usize = @min(line.len, @as(usize, @intCast(@max(0, w.at)))); + const next = pane.wrapAt(tab, row + 1); + const to: usize = if (next.line == w.line) @min(line.len, @as(usize, @intCast(@max(0, next.at)))) else line.len; + // Right to left, so a push leaves the places before it where they are. + var end = to; + while (std.mem.lastIndexOf(u8, line[from..end], old)) |k| { + const at = from + k; + end = at; + const before = at > 0 and (std.ascii.isAlphanumeric(line[at - 1]) or line[at - 1] == '_'); + const after = at + old.len < line.len and (std.ascii.isAlphanumeric(line[at + old.len]) or line[at + old.len] == '_'); + if (before or after) continue; + const c0 = gutter + w.pad + File.displayOffset(tab, pane, w.line, w.at, @intCast(at)); + const c1 = gutter + w.pad + File.displayOffset(tab, pane, w.line, w.at, @intCast(at + old.len)); + if (c0 < gutter or c1 > tw) continue; + const y = body_y + row; + var c: u16 = @intCast(c0); + while (c < c1) : (c += 1) { + const cell = s.at(tx + c, y); + cell.style.strikethrough = true; + cell.style.fg = .{ .rgb = chrome.diagnostic_error }; + } + const x: u16 = @intCast(c1); + if (x + wide < tw) { + const cells = s.cells[@as(usize, y) * s.cols + tx ..][0..tw]; + std.mem.copyBackwards(Cell, cells[x + wide ..], cells[x .. tw - wide]); + } + _ = s.print(tx + x, y, tw - x, new, added); + } + } +} + /// The line a motion role would go to from the caret of `pane`, looked for /// in lines `lo` to `hi` (the rows shown) alone; null for none there, or a /// role that is no line's. diff --git a/core/builtins.zig b/core/builtins.zig index eac52555..ffb82c4b 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -2275,6 +2275,9 @@ pub const Rename = struct { pub fn run(c: Ctx) void { const a = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); if (a.len > 0) return c.p.lspRequest(c.id, .rename, a); + // From the keyboard, where the walk is on: typed in the pane's own + // tag, its edits drawn in its body as they are typed (SPEC §3.5). + if (pardes.Pick.asked(c.p) and c.pane.file != null) return @import("lsp/Ask.zig").openRename(c.p, c.id); panes.startPrompt(c.p, c.pane, &c.pane.body, .{ .search = config.rename_marker }); } }; diff --git a/core/keys.zig b/core/keys.zig index 651d6417..6dea7278 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -213,6 +213,12 @@ pub fn handleKey(p: *Pardes, key: Key) void { } // A tag in a typing state takes every key (TagState: Help, describe-key). if (p.view().tag_state.kind != .rest) return tagStateKey(p, key); + // Esc takes a hover's ghost lines away (SPEC §3.5) before anything else + // it does. + if (p.lsp_ask.hover != null and hit(key, config.escape)) { + p.lsp_ask.hover = null; + return; + } if (p.view().window_pick != null) return layout.windowKey(p, key); const pane = p.panes[p.view().active] orelse return; layout.noteTyped(p); @@ -583,6 +589,7 @@ fn tagStateKey(p: *Pardes, key: Key) void { TagState.describeKey(p, key); }, .pick => return @import("Pick.zig").key(p, key), + .rename => return @import("lsp/Ask.zig").renameKey(p, key), .help => { const plain = !key.ctrl and !key.alt; if (plain and key.cp == Key.enter) { diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig index 976821d5..f8cb8cfc 100644 --- a/core/lsp/Ask.zig +++ b/core/lsp/Ask.zig @@ -18,6 +18,7 @@ const memory = @import("../memory.zig"); const Pardes = pardes.Pardes; const Pane = panes.Pane; const Effect = pardes.Effect; +const TagState = @import("../TagState.zig"); const Ask = @This(); @@ -38,6 +39,12 @@ wait: ?struct { row: i32 = 0, col: i32 = 0, } = null, +/// A hover asked from the keyboard (where the walk is on), drawn as ghost +/// lines under the line it was asked at in its own body (pick-ui SPEC §3.5, +/// the coordinator's R3: never written): until Esc, an edit of that text, +/// or the next hover. Its first `hover_max` bytes. +hover: ?struct { serial: u32, row: i32, revision: u32, text: Effect.Buf(hover_max) } = null, +pub const hover_max = 1024; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8) void { @@ -247,6 +254,48 @@ fn applyLspEdits(p: *Pardes, pane: *Pane, revision: u32, edits: []const LspEdit) return true; } +/// Rename typed in pane `id`'s own tag (SPEC §3.5): the field the name +/// under its caret, which the body shows renamed as it is typed +/// (body_layer.renameGhosts) until Enter asks the server, or Esc. +pub fn openRename(p: *Pardes, id: usize) void { + const pane = p.panes[id] orelse return; + const old = renamedWord(pane) orelse return p.reportFailure(id, "Rename: nothing here to rename"); + TagState.toRest(p); + const s = &p.view().tag_state; + s.kind = .rename; + s.host = pane.serial; + s.field.set(old); + s.previewing.set(id); +} + +/// A key in Rename's field: Enter asks the server to rename to it (a name +/// the same as the old is no question), Esc (the tag's) puts it away. +pub fn renameKey(p: *Pardes, key: pardes.Key) void { + const s = &p.view().tag_state; + if (!key.ctrl and !key.alt and key.cp == pardes.Key.enter) { + const id = TagState.hostOf(p) orelse return TagState.toRest(p); + var name: Effect.Buf(128) = .{}; + const typed = std.mem.trim(u8, s.field.text(), " "); + const same = std.mem.eql(u8, typed, renamedWord(p.panes[id].?) orelse ""); + if (typed.len <= 128) name = .from(typed); + TagState.toRest(p); + if (same) return; + if (typed.len > 128) return p.reportFailure(id, "Rename: a name is at most 128 bytes"); + return lspRequest(p, id, .rename, name.slice()); + } + _ = s.field.key(key); +} + +/// The name under pane `pane`'s caret, which a Rename renames. +pub fn renamedWord(pane: *const Pane) ?[]const u8 { + const line = panes.File.sourceLine(pane, pane.body.cur_row); + var lo: usize = @min(@as(usize, @intCast(@max(0, pane.body.cur_col))), line.len); + var hi = lo; + while (lo > 0 and (std.ascii.isAlphanumeric(line[lo - 1]) or line[lo - 1] == '_')) lo -= 1; + while (hi < line.len and (std.ascii.isAlphanumeric(line[hi]) or line[hi] == '_')) hi += 1; + return if (hi > lo) line[lo..hi] else null; +} + /// The builtin word that asks `kind`, for what it says. fn lspWord(kind: lsp.Kind) []const u8 { return switch (kind) { @@ -333,6 +382,14 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { return; } + // A hover asked from the keyboard: ghost lines in its own body, no + // +Hover pane (SPEC §3.5). + if (w.kind == .hover and pardes.Pick.asked(p)) { + var cut = @min(rows.len, hover_max); + while (cut < rows.len and cut > 0 and rows[cut] & 0xC0 == 0x80) cut -= 1; + p.lsp_ask.hover = .{ .serial = pane.serial, .row = w.row, .revision = w.revision, .text = .from(rows[0..cut]) }; + return; + } const from: panes.Output.Origin = .{ .query = w.kind }; const nrows = std.mem.count(u8, rows, "\n"); if ((panes.Output.traits(from).jumps or w.kind == .diagnostics) and nrows == 1) { @@ -626,3 +683,95 @@ test "LSP failure clears only its matching wait without completion indentation" try std.testing.expectEqualStrings("x ", pane.file.?.content); try std.testing.expectEqual(@as(i32, 4), pane.body.cur_col); } + +test "a hover asked from the keyboard is ghost lines under the line it was asked at, drawn and never written, no +Hover pane; Esc takes them away" { + if (!lsp.supports.contains(.hover)) return error.SkipZigTest; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 20 }); + defer p.deinit(); + const pane = try p.setTestFile("one\ntwo\nthree\nfour\n"); + const id = p.view().active; + p.settings.jumps = .walk; + while (p.nextEffect()) |_| {} + pane.focus = .body; + pane.body.cur_row = 1; + var npanes: usize = 0; + for (p.panes) |slot| npanes += @intFromBool(slot != null); + p.lspRequest(id, .hover, ""); + while (p.nextEffect()) |_| {} + lspResponse(p, p.lsp_ask.seq, "pub fn add(a: i32) i32\nadds them\n"); + var now: usize = 0; + for (p.panes) |slot| now += @intFromBool(slot != null); + try std.testing.expectEqual(npanes, now); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + p.sync(); + var s = try p.render(frame.allocator()); + const body = s.region(.body, id).?.rect; + var buf: [256]u8 = undefined; + try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 1, &buf), "two") != null); + try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "pub fn add(a: i32) i32") != null); + try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "adds them") != null); + try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 4, &buf), "three") != null); + try std.testing.expectEqualStrings("one\ntwo\nthree\nfour\n", pane.file.?.content); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(p.lsp_ask.hover == null); + try std.testing.expectEqual(id, p.view().active); + _ = frame.reset(.retain_capacity); + s = try p.render(frame.allocator()); + try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "three") != null); +} + +/// Grid row `y` of `s` from column `x`, as text. +fn rowText(s: *const pardes.Surface, x: u16, y: u16, buf: []u8) []const u8 { + var n: usize = 0; + for (x..s.cols) |col| { + const g = s.cells[@as(usize, y) * s.cols + col].grapheme(); + if (n + g.len > buf.len) break; + @memcpy(buf[n..][0..g.len], g); + n += g.len; + } + return buf[0..n]; +} + +test "SPC l r types the new name in the pane's own tag, the body showing each place in view renamed as it is typed, never written; Enter asks the server for it, Esc puts it away" { + if (!lsp.supports.contains(.rename)) return error.SkipZigTest; + const Key = pardes.Key; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 20 }); + defer p.deinit(); + const pane = try p.setTestFile("const best = 1;\nconst b = best + best;\nconst bestow = 2;\n"); + const id = p.view().active; + p.settings.jumps = .walk; + pane.focus = .body; + pane.body.cur_row = 0; + pane.body.cur_col = 7; + for (" lr") |c| p.update(.{ .key = .{ .cp = c } }); + const s = &p.view().tag_state; + try std.testing.expectEqual(TagState.Kind.rename, s.kind); + try std.testing.expectEqualStrings("best", s.field.text()); + for ("er") |c| p.update(.{ .key = .{ .cp = c } }); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, a, pane), " Rename best → bester") != null); + p.sync(); + const sf = try p.render(a); + const body = sf.region(.body, id).?.rect; + var buf: [256]u8 = undefined; + // Each `best` in view struck and followed by the new name; `bestow` is + // another word. + try std.testing.expect(std.mem.indexOf(u8, rowText(sf, body.x, body.y, &buf), "const bestbester = 1;") != null); + try std.testing.expect(std.mem.indexOf(u8, rowText(sf, body.x, body.y + 1, &buf), "const b = bestbester + bestbester;") != null); + try std.testing.expect(std.mem.indexOf(u8, rowText(sf, body.x, body.y + 2, &buf), "const bestow = 2;") != null); + try std.testing.expectEqualStrings("const best = 1;\nconst b = best + best;\nconst bestow = 2;\n", pane.file.?.content); + // Enter: the server asked to rename it, the tag at rest. + while (p.nextEffect()) |_| {} + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expectEqual(TagState.Kind.rest, s.kind); + try std.testing.expectEqualStrings("bester", p.lsp_ask.wait.?.arg.slice()); + // Esc from the field asks nothing. + p.lsp_ask.wait = null; + for (" lr") |c| p.update(.{ .key = .{ .cp = c } }); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(TagState.Kind.rest, s.kind); + try std.testing.expect(p.lsp_ask.wait == null); +} -- cgit v1.3