summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 20:51:15 -0300
committerGabriel Schneider <[email protected]>2026-10-29 21:03:37 -0300
commitfdf59131f68db19fc4818b6e5db7c9fe4cc609fd (patch)
tree1d3296044f387ec55f66a8d188279ce3eaaa63dc
parenta8d9eb9e5051521aaeb1a95584729794059b5d83 (diff)
downloadpardes-fdf59131f68db19fc4818b6e5db7c9fe4cc609fd.tar.gz
pardes-fdf59131f68db19fc4818b6e5db7c9fe4cc609fd.zip
pdf: Esc in a PDF pane drops the selection or the search highlights the page shows, and with none goes back a pane as Esc does everywhere else; Shift-Esc still goes at once
Co-Authored-By: Claude Opus 5.5 <[email protected]>
-rw-r--r--docs/helix-keys.md2
-rw-r--r--docs/typ/cheatsheet.typ2
-rw-r--r--docs/typ/guide.typ2
-rw-r--r--src/normal.zig2
-rw-r--r--src/pdf_view.zig14
-rw-r--r--test/pdf.zig29
6 files changed, 39 insertions, 12 deletions
diff --git a/docs/helix-keys.md b/docs/helix-keys.md
index d47f3051..04aa60dd 100644
--- a/docs/helix-keys.md
+++ b/docs/helix-keys.md
@@ -122,7 +122,7 @@ language-backend queries, and the shell pipe.
| `y` | yank each range's text into the register (`"<reg>` names one, else `"`), one value per range | line-yank vim-ism removed (phase 5); yank keeps selection AND cursor (helix). The system clipboard is `"+y` / `SPC y`, helix's own split: a `d` of one character never clobbers what the desktop holds | helix-verified |
| `u` / `U` | undo / redo | restores the pre-edit selection (helix); snapshot granularity, `Alt-u`/`Alt-U` are the same two: helix walks a history tree by time with them, and pardes's history is linear, so earlier and later ARE undo and redo | helix-verified |
| `p` (normal) | paste the register after each range: value i at range i, the last value repeated when there are fewer | helix `paste_impl`. `"+p` asks the system clipboard (`SPC p`); on a tty that read is OSC 52, which most terminals refuse: an honest no-op rather than a paste of the wrong text | helix-verified |
-| `Esc` (body normal) | clear a pending modal prefix / exit select mode, keeping the selection, then run `Last`: hop to the pane you were in before this one, whichever kind it was, exactly like `SPC j j` — so held down it alternates between two panes, two files as readily as a file and its shell. A PDF pane is the ONE exception: there Esc is the document's own cancel (drop the mouse selection and the search overlay, stay where you are reading) and `Shift-Esc` is the hop out, while raw tty takes unmodified Esc as `Last` and sends Shift-Esc to the program (with `ProgramEsc on`, Esc goes to the program except at a detected shell prompt) | Pardes-specific focus binding layered on helix's cleanup. A leader path, tag, topbar or search owns Esc while it is active; raw tty forwards it | pardes-specific (cleanup helix-verified) |
+| `Esc` (body normal) | clear a pending modal prefix / exit select mode, keeping the selection, then run `Last`: hop to the pane you were in before this one, whichever kind it was, exactly like `SPC j j` — so held down it alternates between two panes, two files as readily as a file and its shell. In a PDF pane Esc first drops the mouse selection and the search highlights when the page shows any, staying where you are reading, and the next Esc hops; `Shift-Esc` hops at once. Raw tty takes unmodified Esc as `Last` and sends Shift-Esc to the program (with `ProgramEsc on`, Esc goes to the program except at a detected shell prompt) | Pardes-specific focus binding layered on helix's cleanup. A leader path, tag, topbar or search owns Esc while it is active; raw tty forwards it | pardes-specific (cleanup helix-verified) |
| `Esc` (insert) | back to normal mode, cursor right after the insertion (no vim left-step) | | helix-verified |
| `Enter` (normal) | acme **look** chord: EXPLICIT selection, else file-ish word under cursor | pardes-specific, keep (helix normal-mode Enter unbound). Covers helix `gf`. Implicit motion residue falls back to the cursor word | pardes-specific |
| `Tab` (normal) | acme **execute** chord | pardes-specific, keep; explicit-selection rule as Enter | pardes-specific |
diff --git a/docs/typ/cheatsheet.typ b/docs/typ/cheatsheet.typ
index 11f7c6fc..9dc9c473 100644
--- a/docs/typ/cheatsheet.typ
+++ b/docs/typ/cheatsheet.typ
@@ -72,7 +72,7 @@ Helix-style: motions *select*, then an edit acts on the selection. Mode box: bla
== Keys: panes
#pairs(
[#key("Ctrl-w")], [window mode: #keys("h", "j", "k", "l") move the outline, #key("d") deletes it (then #key("k")/#key("j") between two), #key("c") collapses it, #key("Enter")/#key("Esc") or a pane's letter focuses (not in insert or raw `$`)],
- [#key("Esc")], [back to the previous pane (insert: to normal)],
+ [#key("Esc")], [back to the previous pane (insert: to normal; a PDF: its selection and search highlights go first)],
[#key("Shift-Esc")], [back to the previous pane from any mode but raw, where it is the program's Esc; needs the kitty keyboard protocol or the GUI, elsewhere a plain Esc],
[#keys("Ctrl-o", "Ctrl-i")], [jump history back, forward; this file first. #key("Ctrl-i") is #key("Tab") without the kitty protocol: #key("SPC j i")],
[#key("Alt-n")], [new terminal below],
diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ
index 40802ed9..0b721658 100644
--- a/docs/typ/guide.typ
+++ b/docs/typ/guide.typ
@@ -43,7 +43,7 @@ steps raw, normal, insert.
[#mode-box(" ") normal], [#key("Esc"): back to the previous pane (#word("Last")), unlike helix. #key("Shift-Esc"): the same.],
[#mode-box("^") insert], [#key("Esc"): back to normal. #key("Shift-Esc"): out of insert and back to the previous pane.],
[#mode-box("$") raw], [#key("Esc"): back to the previous pane. #key("Shift-Esc"): an Esc to the program. Either way the terminal stays raw. #word("ProgramEsc") `on` swaps them back: #key("Esc") goes to the program, except at a shell prompt with nothing typed on it, and #key("Shift-Esc") always goes back.],
- [a PDF], [#key("Esc"): clears the selection and the search highlights. #key("Shift-Esc"): back to the previous pane.],
+ [a PDF], [#key("Esc"): clears the selection and the search highlights, and with none shown goes back to the previous pane. #key("Shift-Esc"): back at once.],
)
In acme, Esc selects the text typed since the last click; here it leaves
diff --git a/src/normal.zig b/src/normal.zig
index f214121a..25e2deec 100644
--- a/src/normal.zig
+++ b/src/normal.zig
@@ -1016,6 +1016,8 @@ pub fn handlePdfNormal(p: *Pardes, pane: *Pane, key: Key) void {
if (result.page_changed) panes.Pdf.resetPageChrome(pane);
switch (result.host) {
.none => {},
+ // typed again by a macro, Esc is only the page's
+ .last => if (p.macro.replaying == 0) exec.runBuiltin(p, .Last, p.active, "", null),
.leader => {
p.leader_on = true;
p.leader_n = 0;
diff --git a/src/pdf_view.zig b/src/pdf_view.zig
index 4ddbf299..b2b9c5a3 100644
--- a/src/pdf_view.zig
+++ b/src/pdf_view.zig
@@ -906,12 +906,15 @@ pub const State = if (enabled) struct {
if (page) |selected_page| state.invalidateRaster(selected_page);
}
- pub fn cancelChrome(state: *@This(), gpa: std.mem.Allocator) void {
+ /// Drops the selection and the search; true when there was one.
+ pub fn cancelChrome(state: *@This(), gpa: std.mem.Allocator) bool {
+ const had = state.selection != null or state.search_query.len > 0;
state.clearDrag();
state.clearSelection(gpa);
- if (state.search_query.len == 0) return;
+ if (state.search_query.len == 0) return had;
state.dropSearchQuery(gpa);
state.invalidateRaster(state.page);
+ return had;
}
fn invalidatePage(state: *@This(), gpa: std.mem.Allocator) void {
@@ -1230,6 +1233,7 @@ pub const ScrollResult = struct { active_page: usize };
pub const CellPixels = struct { w: u16, h: u16 };
pub const NormalHost = enum {
none,
+ last,
leader,
command_line,
search,
@@ -2476,7 +2480,11 @@ pub fn applyNormal(
if (comptime !enabled) return .{};
var result: NormalResult = .{};
switch (semantic) {
- .escape => state.cancelChrome(gpa),
+ // Esc drops a selection or a search the page shows, else goes back
+ // a pane (text-only, the page shows neither).
+ .escape => if (!state.cancelChrome(gpa) or !native_images) {
+ result.host = .last;
+ },
.move => |move| switch (move.motion) {
.down => result.page_changed = moveRows(
state,
diff --git a/test/pdf.zig b/test/pdf.zig
index 3f84195c..a50f3bf6 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -1454,7 +1454,7 @@ test "PDF normal adapter consumes unsupported actions and navigates page fallbac
try std.testing.expect(pane.prompt == .none);
}
-test "Escape cancels PDF chrome in place and Shift-Escape leaves the pane" {
+test "Escape cancels PDF chrome in place, then leaves the pane; Shift-Escape leaves at once" {
if (!pdf_enabled or platform == .web) return;
const gpa = std.testing.allocator;
@@ -1507,15 +1507,32 @@ test "Escape cancels PDF chrome in place and Shift-Escape leaves the pane" {
try std.testing.expectEqual(scroll_before, pv.document_scroll_y);
try std.testing.expectEqual(@as(u32, 0), pane.body.normal.count);
try std.testing.expectEqual(.none, pane.body.normal.prefix);
- // A second Escape on a bare document is inert rather than an exit.
+ // With nothing left to drop, Escape goes back a pane as anywhere else,
+ // and leaves the document as it found it.
p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(@as(usize, 0), p.active);
-
- // Shift-Escape is the way out, and it leaves the document as it found it.
- p.update(.{ .key = .{ .cp = Key.escape, .shift = true } });
try std.testing.expectEqual(@as(usize, 1), p.active);
try std.testing.expectEqual(page_before, pv.page);
try std.testing.expectEqual(scroll_before, pv.document_scroll_y);
+
+ // Shift-Escape goes at once, over a selection too.
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(
+ panes.Pdf.SelectionUpdate.changed,
+ pv.setSelection(p.pdf_gpa, quad.ul, quad.lr, false),
+ );
+ p.update(.{ .key = .{ .cp = Key.escape, .shift = true } });
+ try std.testing.expectEqual(@as(usize, 1), p.active);
+ try std.testing.expect(pv.selection != null);
+
+ // A text-only page shows neither: one Escape drops them and goes.
+ p.native_images = false;
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try pv.setSearchQuery(p.pdf_gpa, "Pardes");
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(usize, 1), p.active);
+ try std.testing.expect(pv.selection == null and pv.search_query.len == 0);
}
test "PDF continuous strip renders every intersecting short page" {