From f3070c04d3eaa0e0d3965478781c2d0b456446bf Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 08:22:47 -0300 Subject: A PDF place `:P:H` whose search hit H is not on page P, or with no search, is a miss with an err, as a page past the last is The second number of a PDF place is a hit of the pane's search (its search rows are `file.pdf:P:H`), and one that named no hit turned to page P silently. pdf State.hitExists asks the pane's search for page P: a hit it does not have, or any hit with no search, is now ` has no search hit H on page P`, on the pane itself (`:P:H`) and from anywhere (`file.pdf:P:H`); a search row's hit is always there. Co-Authored-By: Claude Opus 5.5 --- src/pdf_view.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/pdf_view.zig') diff --git a/src/pdf_view.zig b/src/pdf_view.zig index b307d1f3..d5769ad3 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -547,6 +547,16 @@ pub const State = if (enabled) struct { state.search_results = results; } + /// Whether page `page` (one-based) holds search hit `hit` (one-based) of + /// the pane's search: none asked, no hit is there. + pub fn hitExists(state: *@This(), gpa: std.mem.Allocator, page: usize, hit: usize) bool { + if (hit == 0) return true; + if (state.search_query.len == 0 or page == 0 or page > state.page_count) return false; + var results = state.document.search(gpa, page - 1, state.search_query) catch return false; + defer results.deinit(gpa); + return hit <= results.hit_count; + } + pub fn ensureOutline(state: *@This(), gpa: std.mem.Allocator) ?*const pdf.Outline { if (!state.outline_tried) { state.outline_tried = true; -- cgit v1.3