diff options
Diffstat (limited to 'src/keys.zig')
| -rw-r--r-- | src/keys.zig | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/keys.zig b/src/keys.zig index 2906e870..dbc31f69 100644 --- a/src/keys.zig +++ b/src/keys.zig @@ -175,8 +175,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { pane.isTerminal() and pane.body.mode == .tty and pane.focus == .body and pane.prompt == .none and tagline.focusedHeader(p) == null; if (raw_esc and key.shift) { - p.leader_on = false; - p.ctrl_w_pending = false; + p.prefix = .none; panes.terminal.followOutput(pane); var plain = key; plain.shift = false; @@ -186,8 +185,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { // mode, a pending count, a raw program -- to the previous pane, as // Esc does from normal mode. Nothing under it sees the key. if (raw_esc or hit(key, config.back_out)) { - p.leader_on = false; - p.ctrl_w_pending = false; + p.prefix = .none; if (pane.prompt != .none) { pane.closePrompt(); pane.focus = .body; @@ -209,8 +207,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { // An open prompt takes the keys even when it answers for a header. const header = if (pane.prompt != .none) null else tagline.focusedHeader(p); if (header == null and pane.isTerminal() and pane.body.mode == .tty and pane.focus == .body and pane.prompt == .none) { - p.leader_on = false; - p.ctrl_w_pending = false; + p.prefix = .none; if (key.ctrl and !key.alt and key.cp == p.tty_toggle) return toggleTty(p, p.active); // With ProgramEsc on, bare Escape leaves only at a shell prompt @@ -234,9 +231,9 @@ pub fn handleKey(p: *Pardes, key: Key) void { } return panes.terminal.forwardKey(p, p.active, key); } - if (p.leader_on) return leaderKey(p, key); - if (p.ctrl_w_pending) { - p.ctrl_w_pending = false; + if (p.prefix == .leader) return leaderKey(p, key); + if (p.prefix == .window) { + p.prefix = .none; for (config.window_keys) |wk| { if (hit(key, &.{ wk.letter, wk.arrow })) return exec.runBuiltin(p, wk.cmd, p.active, "", null); } @@ -248,7 +245,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { const t = header orelse if (pane.focus == .tag) &pane.tag else &pane.body; if (hit(key, config.window_prefix) and t.mode != .insert and (header != null or pane.prompt == .none)) { if (header != null) { - p.ctrl_w_pending = true; + p.prefix = .window; return; } return exec.runBuiltin(p, .Window, p.active, "", null); @@ -432,7 +429,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { } fn leaderKey(p: *Pardes, key: Key) void { - p.leader_on = false; // only "still a prefix" below re-arms it + p.prefix = .none; // only "still a prefix" below re-arms it if (key.ctrl or key.alt or key.cp < 0x20 or key.cp > 0x7e) return; const c: u8 = @intCast(key.cp); if (c == config.leader_help) { @@ -448,7 +445,7 @@ fn leaderKey(p: *Pardes, key: Key) void { // sources with no word of their own). for (config.leader_args) |la| if (std.mem.eql(u8, la.path, pfx)) return exec.runBuiltin(p, la.cmd, p.active, "", la.arg); for (config.leader_args) |la| if (std.mem.startsWith(u8, la.path, pfx)) { - p.leader_on = true; + p.prefix = .leader; }; // a path-less builtin is a row here too (it is the same index Help // reads), and SPC cannot reach one — so both scans skip it; and a @@ -460,7 +457,7 @@ fn leaderKey(p: *Pardes, key: Key) void { for (builtin_rows) |row| { if (!builtins.registry.here(p, row.cmd)) continue; if (std.mem.startsWith(u8, row.path orelse continue, pfx)) { - p.leader_on = true; + p.prefix = .leader; return; } } @@ -758,7 +755,7 @@ test "raw tty forwards Ctrl letters and former global shortcuts to the child" { try std.testing.expectEqualStrings(encoded, test_api.ptyBytes(p, null, &buf)); try std.testing.expectEqual(@as(usize, 0), p.active); try std.testing.expectEqual(Text.Mode.tty, p.panes[0].?.body.mode); - try std.testing.expect(!p.ctrl_w_pending and p.clip_pending == null); + try std.testing.expect(p.prefix != .window and p.clip_pending == null); } // ...and the two paste chords are the exception: Ctrl-V types the register // at the program, Ctrl-Shift-V asks the desktop first and types nothing yet. |
