diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-01 08:22:47 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 08:53:11 -0300 |
| commit | f3070c04d3eaa0e0d3965478781c2d0b456446bf (patch) | |
| tree | 56cc5dd8138f7fd83755133798253ec2220ecd32 /src/pdf_view.zig | |
| parent | c5c9768bed2368c6a341d0400b13b3428c138b6e (diff) | |
| download | pardes-f3070c04d3eaa0e0d3965478781c2d0b456446bf.tar.gz pardes-f3070c04d3eaa0e0d3965478781c2d0b456446bf.zip | |
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 `<file> 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 <[email protected]>
Diffstat (limited to 'src/pdf_view.zig')
| -rw-r--r-- | src/pdf_view.zig | 10 |
1 files changed, 10 insertions, 0 deletions
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; |
