diff options
Diffstat (limited to 'core/keys.zig')
| -rw-r--r-- | core/keys.zig | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/core/keys.zig b/core/keys.zig index 6dea7278..e9be2461 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -20,6 +20,7 @@ const Pipe = @import("Pipe.zig"); const Registers = @import("Registers.zig"); const bindings = @import("bindings.zig"); const TagState = @import("TagState.zig"); +const Prompt = @import("Prompt.zig"); const Pardes = pardes.Pardes; const Pane = panes.Pane; const Text = panes.Text; @@ -211,8 +212,26 @@ pub fn handleKey(p: *Pardes, key: Key) void { } return; } + // A background question SPC e gave the keyboard: one of its answers' + // keys answers it (Diff leaves it asking), Esc leaves it waiting, and + // nothing else gets past it (pick-ui SPEC §10.4). + if (p.view().answering != 0) answering: { + const v = p.view(); + const at = p.paneBySerial(v.answering) orelse break :answering; + const i = p.messages.waiting(p.panes[at].?) orelse break :answering; + if (key.cp == Key.escape and !key.ctrl and !key.alt) { + v.answering = 0; + p.needs_frame = true; + return; + } + if (key.ctrl or key.alt or key.cp > 0x7f) return; + if (pardes.Messages.answer(p, i, @intCast(key.cp)) and key.cp != 'd') v.answering = 0; + return; + } + p.view().answering = 0; // A tag in a typing state takes every key (TagState: Help, describe-key). if (p.view().tag_state.kind != .rest) return tagStateKey(p, key); + Prompt.keyAtRest(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)) { @@ -366,8 +385,9 @@ pub fn handleKey(p: *Pardes, key: Key) void { .save => if (submit) exec.submitSave(p, p.view().active), .search => if (submit) look.submitSearch(p, p.view().active) - else if (normal.selRegexArmed(pane)) |_| if (target) |answered| - normal.applySelRegex(p, pane, answered, "", .select), + else if (normal.selRegexArmed(pane)) |_| if (target) |answered| { + _ = normal.applySelRegex(p, pane, answered, "", .select); + }, .none, .del_side, .repl_choice, .name => unreachable, } pane.closePrompt(); @@ -378,7 +398,9 @@ pub fn handleKey(p: *Pardes, key: Key) void { return; } edit.handleInsert(p.editor(), &pane.input, key); - if (normal.selRegexArmed(pane)) |a| if (panes.promptTarget(p, pane)) |answered| normal.applySelRegex(p, pane, answered, a.pat, a.mode); + if (normal.selRegexArmed(pane)) |a| if (panes.promptTarget(p, pane)) |answered| { + _ = normal.applySelRegex(p, pane, answered, a.pat, a.mode); + }; return; } if (header == null) if (TagState.current(p, p.view())) |cur| if (cur.root != .leader and cur.root != .window) { @@ -562,9 +584,10 @@ fn leaderTake(p: *Pardes, c: u8) void { fn tagStateKey(p: *Pardes, key: Key) void { const v = p.view(); const s = &v.tag_state; + if (s.kind == .prompt) return Prompt.key(p, key); if (TagState.hostOf(p) == null or hit(key, config.escape)) return TagState.toRest(p); switch (s.kind) { - .rest => unreachable, + .rest, .prompt => unreachable, .describe => { const plain = !key.ctrl and !key.alt; if (plain and key.cp == Key.enter and s.found) { @@ -837,7 +860,7 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" { // A word that is not a side closes nothing. try std.testing.expect(p.executeBuiltinLine(again, "Del x")); - try std.testing.expectEqualStrings("Del: takes k, j or nothing", p.panes[again].?.msg[0..p.panes[again].?.msg_len]); + try std.testing.expectEqualStrings("Del: takes k, j or nothing", p.messages.saidBy(p.panes[again].?)); try std.testing.expect(p.panes[again] != null); // DelAbove is Del k, and a line that is not a key never asks. try std.testing.expect(p.executeBuiltinLine(again, "DelAbove")); |
