summaryrefslogtreecommitdiff
path: root/src/pdf_pane_integration_test.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdf_pane_integration_test.zig')
-rw-r--r--src/pdf_pane_integration_test.zig62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/pdf_pane_integration_test.zig b/src/pdf_pane_integration_test.zig
index b290616e..2e671f49 100644
--- a/src/pdf_pane_integration_test.zig
+++ b/src/pdf_pane_integration_test.zig
@@ -906,6 +906,68 @@ test "PDF normal adapter consumes unsupported actions and navigates page fallbac
try std.testing.expect(!pane.tag_edit);
}
+test "Escape cancels PDF chrome in place and Shift-Escape leaves the pane" {
+ if (!pdf_enabled or platform == .web) return;
+
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{
+ .file = "docs/design.pdf",
+ .cols = 80,
+ .rows = 28,
+ });
+ defer p.deinit();
+ const pane = p.panes[0].?;
+ const pv = &pane.pdf.?;
+ p.native_images = true;
+
+ // A second pane, then focus it and come back: `Last` has somewhere to go
+ // and the PDF is where the keys land.
+ pdf_pane.openSections(p, 0);
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ p.update(.{ .key = .{ .cp = 'j' } });
+ try std.testing.expectEqual(@as(usize, 1), p.active);
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ p.update(.{ .key = .{ .cp = 'k' } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+
+ // Everything a reader can see over the page: a search overlay and a live
+ // word selection.
+ try pv.setSearchQuery(p.pdf_gpa, "Pardes");
+ var found = try pv.document.search(gpa, pv.page, "Pardes");
+ defer found.deinit(gpa);
+ try std.testing.expect(found.quads.len > 0);
+ const quad = found.quads[0].quad;
+ try std.testing.expectEqual(
+ pdf_pane.SelectionUpdate.changed,
+ pv.setSelection(p.pdf_gpa, quad.ul, quad.lr, false),
+ );
+ p.update(.{ .key = .{ .cp = '3' } });
+ const page_before = pv.page;
+ const scroll_before = pv.document_scroll_y;
+
+ // Escape drops the overlay and the selection, keeps the reading position,
+ // and does NOT hand the keyboard to another pane.
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expect(pv.selection == null and pv.selection_text.len == 0);
+ try std.testing.expectEqual(@as(usize, 0), pv.search_query.len);
+ try std.testing.expect(pv.search_results == null);
+ try std.testing.expect(!pv.highlights_dirty and !pv.search_reveal_pending);
+ try std.testing.expectEqual(page_before, pv.page);
+ try std.testing.expectEqual(scroll_before, pv.document_scroll_y);
+ try std.testing.expectEqual(@as(u32, 0), pane.count);
+ try std.testing.expectEqual(@as(u21, 0), pane.pending);
+ // A second Escape on a bare document is inert rather than an exit.
+ 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);
+}
+
test "PDF continuous strip renders every intersecting short page" {
if (!pdf_enabled or platform == .web) return;