diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Core.zig | 9 | ||||
| -rw-r--r-- | src/Messages.zig | 6 | ||||
| -rw-r--r-- | src/config.zig | 4 | ||||
| -rw-r--r-- | src/gui/gui.zig | 2 | ||||
| -rw-r--r-- | src/keys.zig | 25 | ||||
| -rw-r--r-- | src/normal.zig | 2 | ||||
| -rw-r--r-- | src/pdf_view.zig | 2 | ||||
| -rw-r--r-- | src/views.zig | 2 |
8 files changed, 25 insertions, 27 deletions
diff --git a/src/Core.zig b/src/Core.zig index 9219cc0e..c5665cb5 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -246,7 +246,6 @@ look_hover_refused: ?look.LookHoverWait = null, look_hover_preview: ?look.LookHoverPreview = null, pdf_hover_preview: if (pdf_enabled) ?look.PdfWordPreview else void = if (pdf_enabled) null else {}, wheel_guard: u8 = 0, -ctrl_w_pending: bool = false, /// While a key is replayed across the ranges (normal.replaySels): which /// range this pass is, in document order, how many there are, and /// whether this is the first pass; outside a replay, the one range and @@ -258,7 +257,9 @@ multi_count: usize = 1, /// The register the running normal command names (`"<reg>`); 0 for the /// default one. register: u21 = 0, -leader_on: bool = false, +/// A key that waits for the next: the leader (SPC) or the window prefix +/// (Ctrl-w), one at a time. +prefix: enum { none, leader, window } = .none, /// Window mode's outlined pane (layout.windowKey); null outside it. window_pick: ?usize = null, leader_keys: [4]u8 = undefined, @@ -2408,11 +2409,11 @@ test "TreeContext tag style preserves message rows and its opt-out survives rest try std.testing.expect(band.viewport.w < r.w - config.GUTTER); try std.testing.expectEqualStrings("!", band.cells[layout.tagCapacity(p, band.viewport.w) - 2].grapheme()); pane.msg_len = 0; - p.leader_on = true; + p.prefix = .leader; p.sync(); _ = try p.render(p.scratch.allocator()); try std.testing.expectEqual(full_height, p.surface.body_layers[0].viewport.h); - p.leader_on = false; + p.prefix = .none; try std.testing.expect(p.executeBuiltinLine(0, "TreeContextTagStyle")); p.sync(); _ = try p.render(p.scratch.allocator()); diff --git a/src/Messages.zig b/src/Messages.zig index fbcc0343..8eb18f1d 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -522,7 +522,7 @@ fn collectBands(p: *Pardes, pane: *Pane, r: Rect, id: usize) void { // new one lands under them; when rows run out the oldest go first. for (pane.msg_older[0..pane.msg_older_len], 0..) |line, i| pane.notices.pushAt(.older, @intCast(i), line.slot); if (pane.msg_len > 0) pane.notices.pushAt(.message, 0, pane.msg_slot); - if (id == p.active and p.leader_on) pane.notices.push(.leader); + if (id == p.active and p.prefix == .leader) pane.notices.push(.leader); // Del's question shows once its delay is up: answered before that, it // was never there. const del_waiting = pane.prompt == .del_side and pane.question_due_ns > p.clock.now_ns; @@ -836,7 +836,7 @@ test "notices stack over the body's top rows without moving them" { // A message and a leader prefix at once: two chips, in the order // collectNotices chose, each one row tall and each one row further down. try std.testing.expect(p.executeBuiltinLine(id, "Msg first")); - p.leader_on = true; + p.prefix = .leader; p.leader_n = 0; _ = frame.reset(.retain_capacity); _ = try p.render(frame.allocator()); @@ -861,7 +861,7 @@ test "notices stack over the body's top rows without moving them" { try std.testing.expect(pane.notices.left[0] < pane.notices.left[1]); // Gone with the notices: no stale chip left behind. - p.leader_on = false; + p.prefix = .none; pane.msg_len = 0; _ = frame.reset(.retain_capacity); _ = try p.render(frame.allocator()); diff --git a/src/config.zig b/src/config.zig index 4b56cfa7..1c4e92a1 100644 --- a/src/config.zig +++ b/src/config.zig @@ -206,9 +206,9 @@ test "Space-k is unbound while Exit, Kill and other k chords remain available" { pane.body.cur_row = 1; while (p.nextEffect()) |_| {} p.update(.{ .key = .{ .cp = ' ' } }); - try std.testing.expect(p.leader_on); + try std.testing.expect(p.prefix == .leader); p.update(.{ .key = .{ .cp = 'k' } }); - try std.testing.expect(!p.leader_on and !p.quit); + try std.testing.expect(p.prefix != .leader and !p.quit); try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); while (p.nextEffect()) |effect| try std.testing.expect(effect != .quit); p.update(.{ .key = .{ .cp = 'k' } }); diff --git a/src/gui/gui.zig b/src/gui/gui.zig index a54a4b7b..99609e5e 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -5815,7 +5815,7 @@ test "the layer cover is the per-cell layer scan, over a core's layouts and rand for (0..32) |step| { core.settings.tag_bottom = step & 1 != 0; if (step & 3 == 0) try std.testing.expect(core.executeBuiltinLine(2, "Collapse")); - core.leader_on = step & 4 != 0; + core.prefix = if (step & 4 != 0) .leader else .none; if (step & 8 != 0) { try std.testing.expect(core.executeBuiltinLine(0, "Msg a message chip over the body")); try std.testing.expect(core.executeBuiltinLine(3, "Msg another")); 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. diff --git a/src/normal.zig b/src/normal.zig index 1209fb1e..96c61fba 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -827,7 +827,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void { .increment => return edit.normalAdjustNumber(p, t, @intCast(a.count)), .decrement => return edit.normalAdjustNumber(p, t, -@as(i64, @intCast(a.count))), .leader => if (p.macro.replaying == 0) { - p.leader_on = true; + p.prefix = .leader; p.leader_n = 0; }, // `:` is the one key a tag and a body do not share: it moves the diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 10e21a54..8e9c1517 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -2359,7 +2359,7 @@ pub fn applyNormal(core: *pardes.Pardes, pane: *pardes.Pane, a: modal.Normal.Act .half_page_down, .page_down => movePage(state, gpa, native, viewport, cells, 1, a.role == .half_page_down, a.count), .half_page_up, .page_up => movePage(state, gpa, native, viewport, cells, -1, a.role == .half_page_up, a.count), .leader => { - core.leader_on = true; + core.prefix = .leader; core.leader_n = 0; return; }, diff --git a/src/views.zig b/src/views.zig index f28cabe1..dff25af6 100644 --- a/src/views.zig +++ b/src/views.zig @@ -42,7 +42,7 @@ pub const fields = [_][:0]const u8{ "hover_col", "hover_row", "pointer_raw_col", "pointer_raw_row", "pointer_body_hit", "pointer_tag_hit", "raw_hover_intent", "pointer_inside", "last_click", "click_as", "chord_hold", "wheel_guard", - "ctrl_w_pending", "register", "leader_on", "window_pick", + "prefix", "register", "window_pick", "leader_keys", "leader_n", "header", "header_drag", "header_sweep", "header_scroll", "header_top", "chord_arg", "clip_pending", |
