diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 19:31:05 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 19:31:05 -0300 |
| commit | f44d1b7d040acf674814be3cde336527833450e9 (patch) | |
| tree | 9c22c45541f16e4281a0a504084e3cf6e389d1c8 /core/keys.zig | |
| parent | 326a2bac9558da0ff78987e697546a363b2b8e59 (diff) | |
| download | pardes-f44d1b7d040acf674814be3cde336527833450e9.tar.gz pardes-f44d1b7d040acf674814be3cde336527833450e9.zip | |
TagState, Field, Band: the typing state, and Help over the binding tree (walk UI, pick-ui SPEC.md §3.2's typing row and §4.5, item 4 of line A): a tag's typing state is the view's (TagState.kind help, its host pane by serial, the hostOf every tag's text asks), its box `^` whatever the body's mode, its caret a bar at the field's (the body's caret and its layer's put by while the head is typed in), and it takes every key before anything but a question (keys.zig tagStateKey: Esc back to rest, Enter runs the row typed as its keys, Backspace on an empty field back to the level `?` was struck from, unrolled); SPC ? is Help over every leaf of every root (SPC's, g m z Z [ ]'s, window mode's, the addons' words) and `?` down a level or under a helix prefix Help for that level's (SPC l ?, g ?); its head ` Help ␣ l <field> n/N`; its rows `chord · word · group` scored by the query pane's scorer (Names.match, now pub) on each key into the view's fixed hits (max_hits: the tree's 160 leaves and the registry's 64 words; best first, the tree's order while the field is empty), the band shows eleven around the cursor, the query's bytes in the match tint, the cursor's leaf's doc beside them; `Help <name>` stays the word's +Help; FOR THE PICKERS AND PROMPTS, as they are: Field (core/Field.zig: a one-line field in a fixed 256-byte buffer with its caret, each view's in TagState.field; Field.key takes a line editor's keys: characters, Backspace/C-h, Delete/C-d, Left/C-b, Right/C-f, Home/C-a, End/C-e, C-u, C-k, C-w/M-Backspace, M-b, M-f; false for a key it has no use for, Enter, Esc, the arrows, which its owner takes; set, insert, clear) and Band.Cursor (a list's cursor, TagState.rows: Cursor.key steps it on Down/C-j/C-n, Up/C-k/C-p, PageDown/PageUp; Cursor.window(n) is the eleven rows [lo, hi) a band shows around it); a state's head is a TagState.Head {text, spans, caret}, its band Band.of's switch on TagState.kind; TagState.follow takes no argument now (a root a state puts back is current already: Help's Backspace keeps its level unrolled); TESTS: Field.zig's (a line editor's keys, and the keys it leaves), TagState.zig's two (SPC ? over every root, filtered, the box and the caret, Enter runs Wrap; SPC l ? and g ? scoped, Backspace back to the level unrolled, Esc to rest); core-test 1003 pass, 166 skip, 0 fail
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/keys.zig')
| -rw-r--r-- | core/keys.zig | 81 |
1 files changed, 74 insertions, 7 deletions
diff --git a/core/keys.zig b/core/keys.zig index 1a172045..6f43e166 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -195,8 +195,7 @@ pub fn answerQuestion(p: *Pardes, id: usize, choice: ?u8) bool { pub fn handleKey(p: *Pardes, key: Key) void { // A root this key strikes starts its which-key delay; one it ends // takes its level away (TagState). - const root_was = if (TagState.current(p, p.view())) |cur| cur.root else null; - defer TagState.follow(p, root_was); + defer TagState.follow(p); // A double-click is two clicks with nothing between them. p.view().last_click = null; if (p.macro.recording != 0 and p.macro.replaying == 0) Macro.append(&p.macro.recorded, p.gpa, key) catch |err| p.reportError(.at(p.view().active), "macro", err); @@ -212,6 +211,8 @@ pub fn handleKey(p: *Pardes, key: Key) void { } return; } + // A tag in a typing state takes every key (TagState: Help, describe-key). + if (p.view().tag_state.kind != .rest) return tagStateKey(p, key); if (p.view().window_pick != null) return layout.windowKey(p, key); const pane = p.panes[p.view().active] orelse return; layout.noteTyped(p); @@ -512,11 +513,9 @@ fn leaderTake(p: *Pardes, c: u8) void { const v = p.view(); const s = &v.tag_state; v.prefix = .none; // only "still a level" below re-arms it - if (c == config.leader_help) { - panes.Output.openHelp(p, v.active, v.leader_keys[0..v.leader_n]) catch |err| - p.reportError(.at(v.active), "help", err); - return; - } + // `SPC ?`: Help over every root's leaves; `?` down a level, Help for + // that level's (SPEC §4.5). + if (c == config.leader_help) return TagState.openHelp(p, if (v.leader_n == 0) null else .leader, v.leader_keys[0..v.leader_n]); const path = v.leader_keys[0..v.leader_n]; var children: [bindings.max_children]bindings.Child = undefined; const child = for (bindings.level(p, .leader, path, &children)) |child| { @@ -544,6 +543,70 @@ fn leaderTake(p: *Pardes, c: u8) void { } } +/// A key in a tag's typing state: Esc back to rest; Enter runs the row, +/// typed as its keys; the rows' cursor; the field; Backspace on an empty +/// field back to the level `?` was struck from. +fn tagStateKey(p: *Pardes, key: Key) void { + const v = p.view(); + const s = &v.tag_state; + if (TagState.hostOf(p) == null or hit(key, config.escape)) return TagState.toRest(p); + switch (s.kind) { + .rest => unreachable, + .describe => return TagState.toRest(p), + .help => { + const plain = !key.ctrl and !key.alt; + if (plain and key.cp == Key.enter) { + if (s.nhits == 0) return; + var buf: [TagState.row_max]u8 = undefined; + const leaf = TagState.helpLeaf(p, s.hits[s.rows.at], &buf); + var out: [16]Key = undefined; + const typed = bindings.keysOf(leaf.root, leaf.path, &out); + TagState.toRest(p); + for (typed) |k| handleKey(p, k); + return; + } + if (plain and key.cp == Key.backspace and s.field.len == 0) return helpBack(p); + if (s.rows.key(key, s.nhits)) return; + if (s.field.key(key)) TagState.filter(p); + }, + } +} + +/// Help left by Backspace on its empty field: the level it was struck +/// from, unrolled, as `?` found it; rest from `SPC ?`. +fn helpBack(p: *Pardes) void { + const v = p.view(); + const s = &v.tag_state; + const root = s.scope_root orelse .leader; + var path: [4]u8 = undefined; + const n = s.scope_n; + @memcpy(path[0..n], s.scope[0..n]); + TagState.toRest(p); + const pane = p.panes[v.active] orelse return; + switch (root) { + .leader => { + v.prefix = .leader; + @memcpy(v.leader_keys[0..n], path[0..n]); + v.leader_n = n; + }, + .goto, .match, .view, .view_sticky, .next, .prev => { + const t = if (pane.focus == .tag) &pane.tag else &pane.body; + t.normal.prefix = switch (root) { + .goto => .goto_prefix, + .match => .match_prefix, + .view, .view_sticky => .view_prefix, + .next => .next_prefix, + .prev => .prev_prefix, + else => unreachable, + }; + t.normal.sticky = root == .view_sticky; + }, + .window, .register => return, + } + s.root = root; + s.unrolled = true; +} + /// What a key does to a which-key level before its root reads it: `up` a /// level (Backspace, and Left or Alt-h unrolled), `take` a child (Enter: /// the cursor's, or rolled the leaf the group ran last; Right or Alt-l @@ -594,6 +657,10 @@ 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 { + 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)) { .taken => return true, .up => { |
