From 198889ab8f78b12c9881a20309a792e419ba1386 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 8 Aug 2026 10:44:56 -0300 Subject: Esc alternates between the last two panes; Toggleterm is gone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Esc ran Toggleterm, which hopped between the newest DOC and the newest TERMINAL. That distinction never earned its keep. It made Esc unpredictable — which of three panes you landed on depended on their kinds, not on where you had been — and it could not alternate between two files at all, which is the case you hit most. Editing two files, Esc did nothing. The replacement already existed. Last (SPC j j) is "the pane you were in before this one, whichever it was": it walks the jump stack for the newest entry naming a different pane and restores its line and column. So Esc, and Shift-Esc in tty, now run Last, and Toggleterm is deleted rather than renamed — a third implementation of "go to the other pane" was the thing to avoid. SPC w t goes with it; the w group is the four directional moves, and the jump group already had SPC j j. Held down, Esc alternates. Two files, a file and its shell, a file and a +Search — all the same, because Last has no notion of kind to get wrong. This depends on the swap in the same series: Last reads the stack backwards, and until hopping stopped appending, the pane you came from could fall off it. windownav.snap needed only its keys and prose changed — its golden did not move at all, which is the useful evidence here: for the one scenario the old builtin handled well, Last produces an identical focus sequence. Coverage for what it did not handle is new: a unit test opens a second FILE by looking its name and asserts Esc alternates between two panes of the SAME kind, which is the case that used to be a no-op. Docs follow: tutor.txt, docs/helix-keys.md, docs/design.typ, and the builtin index goldens, which are now one row shorter. 75/75 snapshots, both unit suites, and the macOS ABI build all pass. --- src/builtins.zig | 44 +++++++++----------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) (limited to 'src/builtins.zig') diff --git a/src/builtins.zig b/src/builtins.zig index 9fa459f2..b1380203 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -526,40 +526,6 @@ pub const Right = struct { } }; -/// The file<->terminal hop. "Latest" is already recorded: the jump stack runs -/// oldest-first and a closing pane hands focus back through the same list — so -/// this walks it instead of keeping a second one. Which side is which: only a -/// shell is a terminal; a file, an image and an output buffer (+Search/+Help) -/// are all DOCS you read, so isTerminal is the whole test. Landing pushes this -/// pane onto that same history, which is why the hop back is the same key. -pub const Toggleterm = struct { - pub fn run(c: Ctx) void { - const want_term = !c.pane.isTerminal(); - var t: ?usize = null; - // any live pane of the other kind: a pane you have never focused (the - // file you started with) is in no history at all - for (c.p.panes, 0..) |slot, k| { - const op = slot orelse continue; - if (k != c.id and op.isTerminal() == want_term) t = k; - } - // ...but the most recently focused one wins - var i = c.p.njumps; - while (i > 0) { - i -= 1; - const hid = c.p.jumps[i].pane; - const hp = c.p.panes[hid] orelse continue; - if (hid != c.id and hp.isTerminal() == want_term) { - t = hid; - break; - } - } - if (t) |target| { - c.p.active = target; - c.p.panes[target].?.pending = 0; - } - } -}; - // ---- the jump group ---- // Where focus HAS BEEN, as three verbs and a list over the one stack pardes @@ -583,12 +549,20 @@ pub const Forward = struct { }; /// vim's Ctrl-^: the pane you were in before this one, whichever it was — the -/// hop you press twice a minute and never want to count steps for. +/// hop you press twice a minute and never want to count steps for. Body-normal +/// Esc is this, which is what makes alternating between two panes one key you +/// hold down: two files, or a file and its shell, or a file and a +Search. /// /// It does NOT move the stack cursor: it goes somewhere, so trackJump records /// it like any other move, and that is exactly what makes it an involution — /// after the hop, the pane you came from is the newest OTHER pane, so pressing /// it again comes straight back. Back/Forward walk history; this one makes it. +/// +/// It replaced a `Toggleterm` that hopped specifically between the newest DOC +/// and the newest TERMINAL. That distinction never earned its keep: it made Esc +/// unpredictable (which of three panes you landed on depended on their kinds), +/// and it could not alternate between two files at all — the case you hit most. +/// "The pane before this one" needs no kinds and is the same key twice. pub const Last = struct { pub fn run(c: Ctx) void { var i = c.p.njumps; -- cgit v1.3