summaryrefslogtreecommitdiff
path: root/core/keys.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/keys.zig')
-rw-r--r--core/keys.zig56
1 files changed, 48 insertions, 8 deletions
diff --git a/core/keys.zig b/core/keys.zig
index c30ef233..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;
@@ -230,6 +231,13 @@ pub fn handleKey(p: *Pardes, key: Key) void {
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)) {
+ 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);
@@ -377,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();
@@ -389,11 +398,13 @@ 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) {
- 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
@@ -418,6 +429,13 @@ pub fn handleKey(p: *Pardes, key: Key) void {
break :word .{ b.lo, b.hi };
};
const txt = shown[span[0]..span[1]];
+ // On a word of the pane's walk, the step's Look or Exec, as a
+ // click there (SPEC §6.3).
+ if (header == null and t.what == .tag) if (tagline.trailAt(p, pane, modal.selectionCursor(shown, range))) |step| {
+ pane.focus = .body;
+ if (cmd == config.look_cmd) pardes.Trail.lookStep(p, p.view().active, step) else pardes.Trail.execStep(p, p.view().active, step);
+ return;
+ };
// A column tag's command acts on that column, empty or not.
p.exec_column = if (header != null) p.headerColumn() else null;
defer p.exec_column = null;
@@ -566,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) {
@@ -593,6 +612,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) {
@@ -696,15 +716,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| {
@@ -714,7 +746,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;
},