summaryrefslogtreecommitdiff
path: root/test/pdf.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-15 18:59:33 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:14 -0300
commitb7914a0bd59334f618b62e0b98271211bbec46b9 (patch)
tree53af62ce0ae022e580e35aadbd952e1656dcfa30 /test/pdf.zig
parent3f4f26e0e40d06427e72f72e760d01adcdc0326c (diff)
downloadpardes-b7914a0bd59334f618b62e0b98271211bbec46b9.tar.gz
pardes-b7914a0bd59334f618b62e0b98271211bbec46b9.zip
Clear previous selections before resolving Look destinations
Diffstat (limited to 'test/pdf.zig')
-rw-r--r--test/pdf.zig26
1 files changed, 17 insertions, 9 deletions
diff --git a/test/pdf.zig b/test/pdf.zig
index 113ed8b9..7a05447e 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -120,8 +120,12 @@ const PdfLinkTests = struct {
defer frame.deinit();
_ = try p.render(frame.allocator());
while (p.nextEffect()) |_| {}
- click(p, try textCell(p, "target.txt"));
+ const target_cell = try textCell(p, "target.txt");
+ try std.testing.expect(panes.Pdf.beginSelection(p, p.panes[0].?, target_cell.col, target_cell.row));
+ try std.testing.expect(p.panes[0].?.pdf.?.selection != null);
+ click(p, target_cell);
try expectOpened(p, null);
+ try std.testing.expect(p.panes[0].?.pdf.?.selection == null);
const choices = for (p.panes, 0..) |slot, id| {
if (id == 0) continue;
if (slot) |pane| if (pane.file) |file| if (file.output != null) break pane;
@@ -146,7 +150,7 @@ const PdfLinkTests = struct {
for (0..(config.look_preview_delay_frames orelse 0)) |_| p.update(.tick);
}
- test "PDF links hover clears on leave page and reload while right drag selects text" {
+ test "PDF links hover clears on leave page and reload while right drag chooses Look text" {
if (!pdf_enabled or platform == .web) return;
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
@@ -181,10 +185,13 @@ const PdfLinkTests = struct {
const label = try textCell(p, "label");
p.update(.{ .mouse = .{ .button = config.look_button, .kind = .press, .col = label.col, .row = label.row } });
p.update(.{ .mouse = .{ .button = config.look_button, .kind = .drag, .col = label.col + 3, .row = label.row } });
- p.update(.{ .mouse = .{ .button = config.look_button, .kind = .release, .col = label.col + 3, .row = label.row } });
- try expectOpened(p, null);
try std.testing.expect(pane.pdf.?.selection != null);
try std.testing.expect(pane.pdf.?.selection_text.len > 0);
+ p.update(.{ .mouse = .{ .button = config.look_button, .kind = .release, .col = label.col + 3, .row = label.row } });
+ try expectOpened(p, null);
+ try std.testing.expect(pane.pdf.?.selection == null);
+ try std.testing.expect(pane.pdf.?.selection_text.len == 0);
+ try std.testing.expect(pane.pdf.?.search_query.len > 0);
}
};
@@ -1844,8 +1851,8 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
}
// A native right-click resolves the same MuPDF-snapped word and feeds it
- // to Look. Search highlights precede selection highlights so the live
- // selection remains visually authoritative where they overlap.
+ // to Look. Resolving it clears the previous selection, leaving the new
+ // search highlights without carrying an old selection into the result.
p.update(.{ .mouse = .{ .button = config.look_button, .kind = .press, .col = word_col, .row = selected_row } });
p.update(.{ .mouse = .{ .button = config.look_button, .kind = .release, .col = word_col, .row = selected_row } });
try std.testing.expect(std.ascii.indexOfIgnoreCase(pv.search_query, "Pardes") != null);
@@ -1855,9 +1862,9 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
p.scratch.allocator(),
panes.Pdf.highlightInput(p, 0, pane),
)).forPage(pv.page);
- try std.testing.expect(highlights.len > 1);
- try std.testing.expectEqual(pdf_impl.HighlightKind.search, highlights[0].kind);
- try std.testing.expectEqual(pdf_impl.HighlightKind.selection, highlights[highlights.len - 1].kind);
+ try std.testing.expect(highlights.len > 0);
+ for (highlights) |highlight| try std.testing.expectEqual(pdf_impl.HighlightKind.search, highlight.kind);
+ try std.testing.expect(pv.selection == null and pv.selection_text.len == 0);
const revision_before_reveal = raster.revision;
const max_document_scroll = @as(f64, @floatFromInt(
pv.document_height -| panes.Pdf.paneViewport(p, pane).?.pixel_h,
@@ -1928,6 +1935,7 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
// Unsupported text-selection actions are consumed by the PDF adapter:
// they neither invent a range over placeholder cells nor disturb the
// native MuPDF selection. The select-button's no-drag click still clears.
+ try std.testing.expect(panes.Pdf.beginSelection(p, pane, word_col, selected_row));
p.update(.{ .key = .{ .cp = 'v' } });
try std.testing.expect(pv.selection != null);
try std.testing.expect(!pane.vsel.active);