diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-30 20:03:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:17 -0300 |
| commit | 741d088c60da40fd811dedc80d8e62753959bfea (patch) | |
| tree | b414fb6f9bf4c246435c356f306a6792db37707b /src/look.zig | |
| parent | b6200709aa5e42f7a3d3702489301c71da8cd65d (diff) | |
| download | pardes-741d088c60da40fd811dedc80d8e62753959bfea.tar.gz pardes-741d088c60da40fd811dedc80d8e62753959bfea.zip | |
A look at a PDF's page past its last is a miss, "has no page N", never the last page in its place
manual.pdf:999 on a twelve-page PDF showed page 12 and said nothing,
so a stale or mistyped page number looked like a place found. It is
now the miss a line past a file's end is, whether the PDF is open (it
stays on its page) or not (nothing opens). A restore or a start-up page
past the end still lands on the last.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/look.zig')
| -rw-r--r-- | src/look.zig | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/look.zig b/src/look.zig index 454074c8..2e8a4b39 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1238,6 +1238,11 @@ test "a miss names a long path by its start and its end, its middle given up to try std.testing.expectEqualStrings("short/path.txt", missText("short/path.txt", &cut)); } +fn missedPage(p: *Pardes, id: usize, path: []const u8, page: usize) void { + var cut: [miss_path_cap + "…".len]u8 = undefined; + missed(p, id, "{s} has no page {d}", .{ missText(path, &cut), page }); +} + fn missedLine(p: *Pardes, id: usize, path: []const u8, line: anytype) void { var cut: [miss_path_cap + "…".len]u8 = undefined; missed(p, id, "{s} has no line {d}", .{ missText(path, &cut), line }); @@ -1688,6 +1693,11 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { // `@p<serial>` names no open pane: a miss, said. if (t.id >= MAX_PANES or p.panes[t.id] == null) return missed(p, id, "no pane {s}", .{pl.path[0..@min(pl.path.len, 32)]}); const target = p.panes[t.id].?; + // A PDF's page past its last is a miss, as a line past a file's + // end is: never the last page in its place (opening one, the + // same: Pdf.openPane's .refuse). + if (comptime pdf_enabled) if (target.pdf) |pv| if (t.at.line > pv.page_count) + return missedPage(p, id, pv.path, t.at.line); const before = p.active; clearNavigationSelection(p, target); focusPaneLine(p, t.id, t.at, .center); @@ -1718,8 +1728,10 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { if (comptime pdf_enabled) if (target.kind == .pdf) { if (focusPaneByPath(p, target.path, target.at)) return; const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - // Said with its path and why, as an image that cannot be read is. - _ = panes.Pdf.openPane(p, free, target.path, target.at.line) catch |err| { + // Said with its path and why, as an image that cannot be read + // is; a page past its last is a miss, as for an open one. + _ = panes.Pdf.openPane(p, free, target.path, target.at.line, .refuse) catch |err| { + if (err == error.NoSuchPage) return missedPage(p, id, target.path, target.at.line); var said: [miss_path_cap + 64]u8 = undefined; var cut: [miss_path_cap + "…".len]u8 = undefined; return p.reportError(id, std.fmt.bufPrint(&said, "look: {s}: not a PDF pardes can read", .{missText(target.path, &cut)}) catch "look: not a PDF pardes can read", err); |
