diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-21 21:42:33 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-22 10:03:15 -0300 |
| commit | 3643635640e97eb2e43730d58fcc46214e21851e (patch) | |
| tree | a096772d1709492a624bb90f06fdc98a60d142ac /src/pardes.zig | |
| parent | 4e89db185fa4e3bfe4358d2da3b76fad0cc7e547 (diff) | |
| download | pardes-3643635640e97eb2e43730d58fcc46214e21851e.tar.gz pardes-3643635640e97eb2e43730d58fcc46214e21851e.zip | |
Window mode: pick the pane to focus with an outline or a label
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 85 |
1 files changed, 71 insertions, 14 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index c885acc2..cb2ebe56 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -2983,9 +2983,7 @@ fn chordName(comptime c: config.Chord) []const u8 { fn shortcutCount(comptime b: Builtin) comptime_int { var count = 0; - for (config.window_keys) |wk| if (wk.cmd == b) { - count += 2; - }; + if (b == .Window) count += 1; for (config.jump_keys) |jk| if (jk.cmd == b) { count += 1; }; @@ -3003,13 +3001,9 @@ fn shortcuts(comptime b: Builtin) []const u8 { @setEvalBranchQuota(20000); var parts: [shortcutCount(b)][]const u8 = undefined; var part: usize = 0; - for (config.window_keys) |wk| { - if (wk.cmd != b) continue; - // the prefix has one spelling and this is it - const pfx = chordName(config.window_prefix[0]) ++ " "; - parts[part] = pfx ++ chordName(wk.letter); - parts[part + 1] = pfx ++ chordName(wk.arrow); - part += 2; + if (b == .Window) { + parts[part] = chordName(config.window_prefix[0]); + part += 1; } for (config.jump_keys) |jk| { if (jk.cmd == b) { @@ -4614,6 +4608,8 @@ pub const Pardes = struct { /// default one. register: u21 = 0, leader_on: bool = false, + /// Window mode's outlined pane (layout.windowKey); null outside it. + window_pick: ?usize = null, leader_keys: [4]u8 = undefined, leader_n: u8 = 0, /// The keyboard is on a header: the column tag `header_column` names, or @@ -6372,6 +6368,7 @@ pub const Pardes = struct { } return; } + if (p.window_pick != null) return layout.windowKey(p, key); const pane = p.panes[p.active] orelse return; p.noteTyped(); // In a raw terminal the two Escs swap unless ProgramEsc is on: Esc @@ -6447,12 +6444,16 @@ pub const Pardes = struct { } return; } - // insert mode owns Ctrl-w (delete word backward, helix); the focus - // prefix applies outside raw tty mode + // insert mode owns Ctrl-w (delete word backward, helix); outside raw + // tty mode it enters window mode, or on a header prefixes a move + // between the headers 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)) { - p.ctrl_w_pending = true; - return; + if (header != null) { + p.ctrl_w_pending = true; + return; + } + return exec.runBuiltin(p, .Window, p.active, "", null); } // global window ops (any mode): Alt-n new terminal below, Alt-c move // the active terminal into a fresh column @@ -8534,6 +8535,61 @@ test "Shift-Esc backs out to the previous pane in every mode, never into raw" { try std.testing.expect(p.active != 0); } +test "window mode moves an outline and focuses it on Enter, Esc or a label" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30 }); + defer p.deinit(); + _ = try p.setTestFile("left\n"); + _ = try p.newShell(1, ""); + try std.testing.expect(layout.splitColumn(p, 0, 1, false)); + p.newScratchBelow(1); + p.sync(); + const lower = for (p.panes, 0..) |slot, id| { + if (slot != null and id > 1) break id; + } else return error.TestExpectedScratch; + p.active = 0; + // Ctrl-w enters it; h/j/k/l move only the outline. + p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); + try std.testing.expectEqual(@as(?usize, 0), p.window_pick); + p.update(.{ .key = .{ .cp = 'l', .text = "l" } }); + try std.testing.expect(p.window_pick != null and p.window_pick.? != 0); + p.update(.{ .key = .{ .cp = 'j', .text = "j" } }); + try std.testing.expectEqual(@as(?usize, lower), p.window_pick); + try std.testing.expectEqual(@as(usize, 0), p.active); + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expectEqual(lower, p.active); + try std.testing.expect(p.window_pick == null); + // SPC w enters it too, and Esc also leaves it on the outlined pane. + p.update(.{ .key = .{ .cp = ' ', .text = " " } }); + p.update(.{ .key = .{ .cp = 'w', .text = "w" } }); + p.update(.{ .key = .{ .cp = 'h', .text = "h" } }); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expect(p.window_pick == null); + // Other keys change nothing. + p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); + p.update(.{ .key = .{ .cp = '!', .text = "!" } }); + try std.testing.expectEqual(@as(?usize, 0), p.window_pick); + p.update(.{ .key = .{ .cp = Key.escape } }); + // `:` focuses the outlined pane's tag. + p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); + p.update(.{ .key = .{ .cp = 'l', .text = "l" } }); + p.update(.{ .key = .{ .cp = ':', .text = ":" } }); + try std.testing.expect(p.active != 0 and p.panes[p.active].?.focus == .tag); + p.update(.{ .key = .{ .cp = Key.escape } }); + // A label goes straight there: the left column's pane is "a". + try std.testing.expectEqual(@as(?u8, 'a'), layout.windowLabel(p, 0)); + try std.testing.expect(p.executeBuiltinLine(p.active, "Window")); + p.update(.{ .key = .{ .cp = 'a', .text = "a" } }); + try std.testing.expectEqual(@as(usize, 0), p.active); + // Painted: the outlined tag's band in the selection colour, a label on each. + try std.testing.expect(p.executeBuiltinLine(p.active, "Window")); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const shown = try p.render(arena.allocator()); + try std.testing.expectEqual(p.theme().sel_bg, shown.tag_layers[0].bg); + try std.testing.expectEqualStrings("a", shown.tag_layers[0].cells[1].text[0..shown.tag_layers[0].cells[1].len]); +} + test "raw tty Ctrl-B switches to editor mode without sending child input" { if (platform == .web) return; const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml" }); @@ -8660,6 +8716,7 @@ test "hopping between two panes does not grow the jump stack" { p.update(.{ .key = .{ .cp = ' ' } }); p.update(.{ .key = .{ .cp = 'w' } }); p.update(.{ .key = .{ .cp = dir } }); + p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqual(want, p.active); } try std.testing.expectEqual(depth, p.njumps); |
