summaryrefslogtreecommitdiff
path: root/src/keys.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 20:53:34 -0300
committerGabriel Schneider <[email protected]>2026-11-05 22:07:55 -0300
commit5b135dc60d4e9f77be0a4f883439f3200ac30d30 (patch)
treeb7a38b6c48eed83e0dd5f6e93110886bd4b02173 /src/keys.zig
parent80d47cd246f37356fd2e705495936f6546613e29 (diff)
downloadpardes-5b135dc60d4e9f77be0a4f883439f3200ac30d30.tar.gz
pardes-5b135dc60d4e9f77be0a4f883439f3200ac30d30.zip
fields #40, a key prefix is one enum: leader_on and ctrl_w_pending, never both, are the session's prefix (none, leader or window); handleKey's three writes of both are one each, and the reads say p.prefix == .leader (Messages.zig, normal.zig, pdf_view.zig, config.zig's test; gui.zig's leader chip on a test step); views.zig's per-view fields name prefix; a dump written before this change loads it as the default once: an Upgrade or Restore from it comes back with no prefix pending, and the wire's semantics change; gates on tui: core-test 960/960, behaviour-test 238/238, pane-test 171/172 (1 skipped), snap all 108 scripts ok; gui unit-test 1518/1519 (1 skipped)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/keys.zig')
-rw-r--r--src/keys.zig25
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.