From 7d359addc420eca66bd1583d8fd8d6a104986a03 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 00:31:38 -0300 Subject: panes: a pane's PDF state is its own allocation, `pdf: ?*Pdf.State` (made by openPane with pdf_gpa, freed by deinitPane), as a terminal's is, where every Pane held the State inline, a text file's and a terminal's too: a Pane is 49232 bytes where it was 88936 (the State 39704), and a replica's rollback copy of a pane without a PDF is that much smaller; the dump and the wire change with it, the walk writing the slot as a pointer to a State where it wrote the State in place, so a dump written before this, or a peer of an older build, gives its PDF panes no PDF (the walk notes `Pane.pdf: its kind changed; its default taken`, and dump.ensureKind makes each a terminal); the 97 uses change form only (a `|*x|` capture or a `&` dropped, normal.zig's one among them), applyNormal untouched Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/body_layer.zig | 2 +- src/builtins.zig | 4 +-- src/colors.zig | 2 +- src/draw.zig | 2 +- src/edit.zig | 6 ++--- src/exec.zig | 2 +- src/fs.zig | 2 +- src/look.zig | 22 ++++++++-------- src/macos.zig | 6 ++--- src/mouse.zig | 2 +- src/ninep/ctl.zig | 2 +- src/ninep/pane.zig | 2 +- src/normal.zig | 2 +- src/panes.zig | 17 ++++++++----- src/pardes.zig | 8 +++--- src/pdf_view.zig | 62 ++++++++++++++++++++++++--------------------- src/tagline.zig | 2 +- test/pdf.zig | 52 ++++++++++++++++++------------------- test/pdf_pointer_bench.zig | 2 +- test/pdf_scroll_bench.zig | 4 +-- test/pdf_sections_bench.zig | 2 +- 21 files changed, 106 insertions(+), 99 deletions(-) diff --git a/src/body_layer.zig b/src/body_layer.zig index 7a4103c3..7b1be4f7 100644 --- a/src/body_layer.zig +++ b/src/body_layer.zig @@ -502,7 +502,7 @@ pub fn bodyText(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 { } if (pane.hasPdf()) { if (comptime pdf_enabled) return panes.Pdf.visibleText( - &pane.pdf.?, + pane.pdf.?, p.pdf_gpa, arena, pane.rows -| BOX_H, diff --git a/src/builtins.zig b/src/builtins.zig index 95a6c692..1afba918 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -983,7 +983,7 @@ pub const PdfFit = struct { pub const enabled = pardes.pdf_enabled; pub const takes_arg = true; pub fn run(c: Ctx) void { - const state = &(c.pane.pdf orelse return); + const state = c.pane.pdf orelse return; if (c.arg != null) { const want = stateArg(c, panes.Pdf.FitMode, "PdfFit", "width or height") orelse return; if (want == state.fit) return; @@ -999,7 +999,7 @@ pub const PdfTint = struct { pub const enabled = pardes.pdf_enabled; pub const takes_arg = true; pub fn run(c: Ctx) void { - const state = &(c.pane.pdf orelse return); + const state = c.pane.pdf orelse return; if (c.arg != null) { const want = stateArg(c, panes.Pdf.TintMode, "PdfTint", "disabled, filtered or full") orelse return; while (state.tint != want) panes.Pdf.toggleTint(c.pane); diff --git a/src/colors.zig b/src/colors.zig index 141e0b0e..9c666d9b 100644 --- a/src/colors.zig +++ b/src/colors.zig @@ -824,7 +824,7 @@ pub fn finishThemeInitialization(p: *Pardes) void { fn invalidateThemeDependentRasters(p: *Pardes) void { if (comptime pdf_enabled) for (p.panes) |slot| { const pane = slot orelse continue; - const pv = &(pane.pdf orelse continue); + const pv = pane.pdf orelse continue; if (pv.tint != .disabled) pv.invalidateAllRasters(); }; } diff --git a/src/draw.zig b/src/draw.zig index 518f0800..1e17df3d 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -1071,7 +1071,7 @@ fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { start = std.mem.lastIndexOf(u8, tag[0..@min(prefix_len, tag.len)], state.path) orelse return null; break :blk state.path; } else if (comptime pdf_enabled) blk: { - break :blk if (pane.pdf) |*state| state.path else return null; + break :blk if (pane.pdf) |state| state.path else return null; } else return null; const basename = if (std.mem.lastIndexOfScalar(u8, name, '/')) |slash| slash + 1 else 0; if (basename == name.len) return null; diff --git a/src/edit.zig b/src/edit.zig index 85ace33f..2ba6d57a 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -182,7 +182,7 @@ fn pasteInto(p: *Pardes, t: *Text, bytes: []const u8) void { } pub fn clipYank(p: *Pardes, pane: *Pane, main_only: bool) void { - if (comptime pdf_enabled) if (pane.pdf) |*pv| { + if (comptime pdf_enabled) if (pane.pdf) |pv| { if (pv.selection_text.len > 0) setClipboard(p, pv.selection_text); return; }; @@ -360,7 +360,7 @@ pub fn spanHas(r: i32, c: i32, ar: i32, ac: i32, br: i32, bc: i32) bool { /// the active modal selection as text (v range or x lines), if any pub fn currentSelText(p: *Pardes, pane: *Pane) ?[]const u8 { - if (comptime pdf_enabled) if (p.native_images) if (pane.pdf) |*pv| + if (comptime pdf_enabled) if (p.native_images) if (pane.pdf) |pv| if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text; if (pane.body.vsel.active) return vselText(p, &pane.body); if (!pane.body.msel.active) return null; @@ -401,7 +401,7 @@ pub fn paneCursorLines(p: *Pardes, t: *Text) ![]const []const u8 { const pane = t.pane() orelse return &.{}; if (pane.file) |*f| return panes.File.cursorLines(arena, pane, f); if (pane.hasPdf()) { - if (comptime pdf_enabled) return panes.Pdf.textLines(&pane.pdf.?, p.pdf_gpa, arena); + if (comptime pdf_enabled) return panes.Pdf.textLines(pane.pdf.?, p.pdf_gpa, arena); unreachable; } return panes.terminal.cursorLines(p, pane); diff --git a/src/exec.zig b/src/exec.zig index 27effda0..4706d11a 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -277,7 +277,7 @@ fn heldPane(p: *Pardes, first: usize, k: usize) ?*Pane { pub fn heldSelection(p: *Pardes, first: usize) ?[]const u8 { for (0..p.panes.len + 2) |k| { const t = heldPane(p, first, k) orelse continue; - if (comptime pdf_enabled) if (p.native_images) if (t.pdf) |*pv| { + if (comptime pdf_enabled) if (p.native_images) if (t.pdf) |pv| { if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text; }; diff --git a/src/fs.zig b/src/fs.zig index 3e80fc1b..207f1018 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1481,7 +1481,7 @@ pub fn unmount(p: *Pardes, name: []const u8) !void { const pane = slot orelse continue; const paths = [_][]const u8{ if (pane.file) |file| file.path else "", - if (comptime pardes.pdf_enabled) (if (pane.pdf) |*pdf| pdf.path else "") else "", + if (comptime pardes.pdf_enabled) (if (pane.pdf) |pdf| pdf.path else "") else "", if (pane.image) |image| image.path else "", Pardes.paneDir(pane), }; diff --git a/src/look.zig b/src/look.zig index a4a64b14..f6095fb9 100644 --- a/src/look.zig +++ b/src/look.zig @@ -596,7 +596,7 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart, if (pane.hasPdf()) { if (comptime pdf_enabled) { const found = try panes.Pdf.searchRows( - &pane.pdf.?, + pane.pdf.?, p.pdf_gpa, pat, start == .cursor, @@ -898,7 +898,7 @@ fn landLookSpot(p: *Pardes, id: usize, pane: *Pane, spot: Pane.LookSpot) void { pub fn cancelLookHover(p: *Pardes) void { if (comptime pdf_enabled) if (p.pdf_hover_preview) |*preview| { if (preview.pane < p.panes.len) if (p.panes[preview.pane]) |pane| { - if (pane.serial == preview.serial) if (pane.pdf) |*pv| + if (pane.serial == preview.serial) if (pane.pdf) |pv| pv.invalidateRaster(preview.probe.page); }; preview.deinit(p.pdf_gpa); @@ -1005,7 +1005,7 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, ke if (pane.hasPdf()) { if (landing == .keep) return; if (comptime pdf_enabled) { - const pv = &pane.pdf.?; + const pv = pane.pdf.?; if (pv.focusLocation(p.pdf_gpa, at.line, at.col)) panes.Pdf.resetPageChrome(pane); } return; @@ -1045,7 +1045,7 @@ fn openPaneTarget(p: *const Pardes, path: []const u8, at: Spot) ?Target { if (tt.image) |iv| if (std.mem.eql(u8, iv.path, path)) { return .{ .pane = .{ .id = i, .at = .{} } }; }; - if (comptime pdf_enabled) if (tt.pdf) |*pv| if (std.mem.eql(u8, pv.path, path)) { + if (comptime pdf_enabled) if (tt.pdf) |pv| if (std.mem.eql(u8, pv.path, path)) { return .{ .pane = .{ .id = i, .at = at } }; }; const ff = if (tt.file) |*f| f else continue; @@ -1073,7 +1073,7 @@ pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void { pane.body.sticky_col = -1; for (0..pane.sel.len) |slot| pane.clearPointerSelection(slot); pane.sel = @splat(.{}); - if (comptime pdf_enabled) if (pane.pdf) |*state| { + if (comptime pdf_enabled) if (pane.pdf) |state| { state.clearDrag(); state.clearSelection(p.pdf_gpa); }; @@ -1148,7 +1148,7 @@ fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 { if (target.id >= p.panes.len) return null; const pane = p.panes[target.id] orelse return null; if (pane.file) |file| return locationText(p, file.path, target.at); - if (comptime pdf_enabled) if (pane.pdf) |*doc| return locationText(p, doc.path, target.at); + if (comptime pdf_enabled) if (pane.pdf) |doc| return locationText(p, doc.path, target.at); if (pane.image) |iv| return locationText(p, iv.path, target.at); var path: [32]u8 = undefined; return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{pane.serial}) catch return null, target.at); @@ -1158,7 +1158,7 @@ fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 { pub fn pdfLinkLocation(p: *Pardes, pane: *const Pane, link: if (pdf_enabled) pdf.Link else void) ?[]const u8 { if (comptime !pdf_enabled) return null; - const state = &(pane.pdf orelse return null); + const state = pane.pdf orelse return null; const id = p.paneIdOf(pane) orelse return null; return switch (link.destination) { .none => null, @@ -1248,7 +1248,7 @@ fn missedHit(p: *Pardes, id: usize, path: []const u8, page: usize, hit: usize) v /// The open PDF pane showing `path`, if one does. fn pdfPaneOf(p: *Pardes, path: []const u8) ?*panes.Pdf.State { if (comptime !pdf_enabled) return null; - for (p.panes) |slot| if (slot) |pane| if (pane.pdf) |*pv| if (std.mem.eql(u8, pv.path, path)) return pv; + for (p.panes) |slot| if (slot) |pane| if (pane.pdf) |pv| if (std.mem.eql(u8, pv.path, path)) return pv; return null; } @@ -1487,7 +1487,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { } const pane = p.panes[target] orelse return; const f = pane.file orelse { - if (comptime pdf_enabled) if (pane.pdf) |*pv| return lookPdfPage(p, id, target, pv, expr); + if (comptime pdf_enabled) if (pane.pdf) |pv| return lookPdfPage(p, id, target, pv, expr); if ((by_serial or path.len == 0) and pane.isTerminal()) return lookTerminalAddress(p, id, target, expr); // Named as the pane is, the bare `:addr` (path empty) included. var serial_name: [32]u8 = undefined; @@ -1606,7 +1606,7 @@ pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void { const id = p.active; const pane = p.panes[id] orelse return; // A PDF's place is its page, the last if it has fewer now. - if (comptime pdf_enabled) if (pane.pdf) |*pv| if (std.mem.eql(u8, pv.path, path)) { + if (comptime pdf_enabled) if (pane.pdf) |pv| if (std.mem.eql(u8, pv.path, path)) { if (at.line > 0 and pv.focusLocation(p.pdf_gpa, @min(at.line, pv.page_count), 0)) panes.Pdf.resetPageChrome(pane); return; }; @@ -1805,7 +1805,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { // 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 (comptime pdf_enabled) if (target.pdf) |pv| { if (t.at.line > pv.page_count) return missedPage(p, id, pv.path, t.at.line); if (!pv.hitExists(p.pdf_gpa, @max(1, t.at.line), t.at.col)) return missedHit(p, id, pv.path, @max(1, t.at.line), t.at.col); }; diff --git a/src/macos.zig b/src/macos.zig index 60f9e00e..af8410e0 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -880,7 +880,7 @@ fn watchInitialGeneration(st: *State, pane: u8, path: []const u8) ?file_watch.Ge const value = st.core.panes[pane] orelse return null; if (value.file) |file| if (std.mem.eql(u8, file.path, path)) return .{ .text = std.hash.Wyhash.hash(0, file.content) }; - if (comptime pardes.pdf_enabled) if (value.pdf) |*pdf| if (std.mem.eql(u8, pdf.path, path)) + if (comptime pardes.pdf_enabled) if (value.pdf) |pdf| if (std.mem.eql(u8, pdf.path, path)) return .{ .pdf = null }; return null; } @@ -998,7 +998,7 @@ fn reloadWatchedFile(st: *State, pane: u8, announce: bool) bool { }, .pdf => |old_identity| pdf: { if (comptime !pardes.pdf_enabled) break :pdf .no_change; - const state_before = if (current.pdf) |*pdf_before| pdf_before else break :pdf .no_change; + const state_before = if (current.pdf) |pdf_before| pdf_before else break :pdf .no_change; if (!std.mem.eql(u8, state_before.path, watched.path)) break :pdf .no_change; const before = file_watch.identify(st.io, watched.path) catch { retryWatchedFile(st, pane, generation); @@ -1012,7 +1012,7 @@ fn reloadWatchedFile(st: *State, pane: u8, announce: bool) bool { const after = st.core.panes[pane] orelse break :pdf .changed_uncommitted; if (after.serial != watched.serial) break :pdf .changed_uncommitted; - const pdf_state = if (after.pdf) |*pdf_after| pdf_after else break :pdf .changed_uncommitted; + const pdf_state = if (after.pdf) |pdf_after| pdf_after else break :pdf .changed_uncommitted; if (!std.mem.eql(u8, pdf_state.path, watched.path)) break :pdf .changed_uncommitted; const after_identity = file_watch.identify(st.io, watched.path) catch { retryWatchedFile(st, pane, generation); diff --git a/src/mouse.zig b/src/mouse.zig index 51a566d9..69d1456e 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -1395,7 +1395,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { fn chordCutPaste(p: *Pardes, cut: bool) void { const s = &p.drag.select; const pane = p.panes[s.id] orelse return; - if (comptime pdf_enabled) if (pane.pdf) |*pv| { + if (comptime pdf_enabled) if (pane.pdf) |pv| { if (!s.chorded) { s.chorded = true; pane.sel[sel_slot].state = .none; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index a1504acb..d075e24e 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -441,7 +441,7 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 { // Then what its tag does not say: Collapse, and a PDF's PdfFit and // PdfTint, in the words they take. if (pane.collapsed) w.writeAll("collapsed ") catch {}; - if (comptime pardes.pdf_enabled) if (pane.pdf) |*pv| w.print("fit:{s} tint:{s} ", .{ @tagName(pv.fit), @tagName(pv.tint) }) catch {}; + if (comptime pardes.pdf_enabled) if (pane.pdf) |pv| w.print("fit:{s} tint:{s} ", .{ @tagName(pv.fit), @tagName(pv.tint) }) catch {}; // Last, the body's mode, which the tag shows as a box: helix's select // is normal mode extending. w.print("mode:{s} ", .{if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode)}) catch {}; diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 3895414b..df0c7975 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -461,7 +461,7 @@ fn readFlag(p: *Pardes, req: Req, on: bool) Reply { /// with the page), null for any other pane. fn pdfText(p: *Pardes, pane: *Pane) ?[]const u8 { if (comptime !pardes.pdf_enabled) return null; - const pv = &(pane.pdf orelse return null); + const pv = pane.pdf orelse return null; return pv.ensureText(p.pdf_gpa); } diff --git a/src/normal.zig b/src/normal.zig index 5bc24b08..986a8116 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -1006,7 +1006,7 @@ pub fn handlePdfNormal(p: *Pardes, pane: *Pane, key: Key) void { .pending, .ignored, .unbound => {}, .action => |semantic| { const result = panes.Pdf.applyNormal( - &pane.pdf.?, + pane.pdf.?, p.pdf_gpa, semantic, p.native_images, diff --git a/src/panes.zig b/src/panes.zig index f7a3cf8a..95917b42 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -61,7 +61,10 @@ pub const Pane = struct { col1: i32, }; - const PdfSlot = if (Pdf.enabled) ?Pdf.State else void; + /// A PDF's state is its own allocation in the pdf region, as a + /// terminal's is its own: inline, its raster slots would be every + /// pane's, and every rollback copy's. + const PdfSlot = if (Pdf.enabled) ?*Pdf.State else void; /// What an open prompt is asking. The answer is typed into `input`. pub const Prompt = union(enum) { @@ -509,12 +512,12 @@ pub const Pane = struct { } pub fn pdfPath(pane: *const Pane) ?[]const u8 { - if (comptime Pdf.enabled) if (pane.pdf) |*pv| return pv.path; + if (comptime Pdf.enabled) if (pane.pdf) |pv| return pv.path; return null; } pub fn pdfPage(pane: *const Pane) ?usize { - if (comptime Pdf.enabled) if (pane.pdf) |*pv| return pv.page; + if (comptime Pdf.enabled) if (pane.pdf) |pv| return pv.page; return null; } @@ -538,7 +541,7 @@ pub const Pane = struct { /// current scroll offset: file top line, or the scrollback offset pub fn scroll(pane: *Pane) i32 { if (pane.file) |f| return @intCast(f.scroll); - if (comptime Pdf.enabled) if (pane.pdf) |*pv| return @intCast(pv.text_scroll); + if (comptime Pdf.enabled) if (pane.pdf) |pv| return @intCast(pv.text_scroll); return pane.surfRow(terminal.gridOffset(pane) + pane.pan); } @@ -576,7 +579,7 @@ pub const Pane = struct { } } else if (hasPdf(pane)) { if (comptime Pdf.enabled) { - const pv = &pane.pdf.?; + const pv = pane.pdf.?; const max: i64 = @intCast(modal.lineCount(pv.text) -| 1); pv.text_scroll = @intCast(std.math.clamp( @as(i64, @intCast(pv.text_scroll)) + delta, @@ -637,7 +640,7 @@ pub const Pane = struct { to = @min(to, if (off == 0 and pane.textFits()) @max(pane.body.cur_row, lines - 1 - @intFromBool(std.mem.endsWith(u8, f.content, "\n"))) else lines - 1); } if (comptime Pdf.enabled) { - if (pane.pdf) |*pv| + if (pane.pdf) |pv| to = @min(to, @as(i32, @intCast(modal.lineCount(pv.text) -| 1))); } pane.scrollBy(@max(0, to - last)); @@ -684,7 +687,7 @@ pub const Pane = struct { pub fn hasPdfSelection(pane: *const Pane) bool { return if (comptime Pdf.enabled) - if (pane.pdf) |*pv| pv.selection != null and pv.selection_text.len > 0 else false + if (pane.pdf) |pv| pv.selection != null and pv.selection_text.len > 0 else false else false; } diff --git a/src/pardes.zig b/src/pardes.zig index 14c6bd98..bc0266c5 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4600,7 +4600,7 @@ pub const Pardes = struct { if (pane.image) |*iv| { iv.deinit(p.image_gpa); } - if (comptime pdf_enabled) if (pane.pdf) |*pv| panes.Pdf.deinitPane(p, pane, pv); + if (comptime pdf_enabled) if (pane.pdf) |pv| panes.Pdf.deinitPane(p, pane, pv); if (pane.file) |*file| panes.File.deinit(p, pane, file); if (pane.ovl) |o| p.gpa.free(o.text); views.tornDown(p, pane); @@ -5743,7 +5743,7 @@ pub const Pardes = struct { layout.compute(p); for (p.panes, 0..) |slot, id| { const pane = slot orelse continue; - if (pane.pdf) |*pv| { + if (pane.pdf) |pv| { if (!std.meta.eql(before[id], panes.Pdf.paneViewport(p, pane))) { panes.Pdf.captureLayoutAnchor(pv); pv.layout_valid = false; @@ -6331,7 +6331,7 @@ pub const Pardes = struct { .none => {}, } if (pane.file) |f| return panes.Dir.ofName(f.path); - if (comptime pdf_enabled) if (pane.pdf) |*pv| + if (comptime pdf_enabled) if (pane.pdf) |pv| return std.fs.path.dirname(pv.path) orelse "/"; if (pane.image) |iv| return std.fs.path.dirname(iv.path) orelse "/"; return pane.cwdSlice(); @@ -7413,7 +7413,7 @@ pub const Pardes = struct { for (p.panes) |slot| if (slot) |pane| if (pane.places.busy(pane)) return next; for (p.panes) |slot| if (slot) |pane| if (pane.image) |iv| if (iv.decoder != null) return next; // A PDF page being rendered on a lane lands on the frame after it is done. - if (comptime pdf_enabled) for (p.panes) |slot| if (slot) |pane| if (pane.pdf) |*st| if (panes.Pdf.rendering(st)) return next; + if (comptime pdf_enabled) for (p.panes) |slot| if (slot) |pane| if (pane.pdf) |st| if (panes.Pdf.rendering(st)) return next; // A markdown text's tables still being read from the top (Tables.zig). for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.tables.busy()) return next; if (panes.Query.busy(p)) return next; diff --git a/src/pdf_view.zig b/src/pdf_view.zig index a0a48178..654284f4 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -2759,7 +2759,9 @@ pub fn openPane( // pane meanwhile. core.reserved_slots[id] = true; defer core.reserved_slots[id] = false; - var state = if (filesystem.localPath(path) != null) + const state = try core.pdf_gpa.create(State); + errdefer core.pdf_gpa.destroy(state); + state.* = if (filesystem.localPath(path) != null) try State.open(core.pdf_gpa, path, page_one_based) else virtual: { const bytes = try filesystem.read(core, path); @@ -2779,7 +2781,7 @@ pub fn openPane( /// armed over it has nothing to reload. pub fn sameBytes(core: *pardes.Pardes, pane: *const pardes.Pane) bool { if (comptime !enabled) return false; - const state = if (pane.pdf) |*pv| pv else return false; + const state = if (pane.pdf) |pv| pv else return false; if (state.file == 0) return false; const bytes = filesystem.read(core, state.path) catch return false; defer core.gpa.free(bytes); @@ -2792,13 +2794,15 @@ pub fn deinitPane(core: *pardes.Pardes, pane: *pardes.Pane, state: *State) void if (comptime !enabled) return; if (core.paneIdOf(pane)) |id| core.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); state.deinit(core.pdf_gpa); + core.pdf_gpa.destroy(state); + pane.pdf = null; } /// A PDF pane loaded from a dump given its document again (MuPDF's, so /// never in the dump) from its file; one changed since is laid out anew. pub fn reopen(core: *pardes.Pardes, pane: *pardes.Pane) !void { if (comptime !enabled) return; - const state = &(pane.pdf orelse return); + const state = pane.pdf orelse return; const local = filesystem.localPath(state.path) orelse return error.NonLocalPath; const bytes = try filesystem.readFile(core.pdf_gpa, local); defer core.pdf_gpa.free(bytes); @@ -2858,7 +2862,7 @@ pub fn reloadWatched( pane: *pardes.Pane, ) !void { if (comptime !enabled) return error.PdfDisabled; - const state = &(pane.pdf orelse return error.MissingPdfState); + const state = pane.pdf orelse return error.MissingPdfState; try state.reload(core.pdf_gpa); resetPageChrome(pane); refreshCleanSections(core, state); @@ -2895,7 +2899,7 @@ fn rearmCleanSections( pub fn openSections(core: *pardes.Pardes, id: usize) void { if (comptime !enabled) return; const pane = core.panes[id] orelse return; - const state = &(pane.pdf orelse return); + const state = pane.pdf orelse return; if (rearmCleanSections(core, id, pane, state)) return; const content = state.renderSections(core.pdf_gpa, core.gpa) catch |err| return core.reportError(id, "PdfSections", err); // No outline: said, not an empty pane to puzzle over. @@ -2945,7 +2949,7 @@ fn sectionsOwner(core: *pardes.Pardes, output_id: usize) ?SectionsOwner { const file = output.file.?; for (core.panes, 0..) |slot, id| { const pane = slot orelse continue; - const state = if (pane.pdf) |*pdf_state| pdf_state else continue; + const state = if (pane.pdf) |pdf_state| pdf_state else continue; const token = state.sections_output orelse continue; if (token.pane == output_id and token.serial == output.serial and token.revision == file.revision) @@ -3017,7 +3021,7 @@ pub fn activatePage( reveal: bool, ) void { if (comptime !enabled) return; - const state = &(pane.pdf orelse return); + const state = pane.pdf orelse return; if (state.activatePage(core.pdf_gpa, page, reveal)) resetPageChrome(pane); } @@ -3028,7 +3032,7 @@ pub fn revealOutlineDestination( ) void { if (comptime !enabled) return; activatePage(core, pane, destination.page, false); - const state = &pane.pdf.?; + const state = pane.pdf.?; state.queueOutlineReveal(destination); // Consume immediately when geometry already exists; otherwise the PDF // draw pass consumes the same value after the next layout transaction. @@ -3044,7 +3048,7 @@ const place_scale: f64 = std.math.maxInt(u32); pub fn place(pane: *const pardes.Pane) ?Place { if (comptime !enabled) return null; - const state = if (pane.pdf) |*pv| pv else return null; + const state = if (pane.pdf) |pv| pv else return null; if (!state.layout_valid or state.document_height == 0) return .{ .page = state.page, .at = 0 }; const page = pageAtOffset(state, state.document_scroll_y); const start: f64 = @floatFromInt(state.page_starts[page]); @@ -3056,7 +3060,7 @@ pub fn place(pane: *const pardes.Pane) ?Place { /// Where `at` stands on the strip as laid out now, in document pixels. pub fn placeY(pane: *const pardes.Pane, at: Place) ?f64 { if (comptime !enabled) return null; - const state = if (pane.pdf) |*pv| pv else return null; + const state = if (pane.pdf) |pv| pv else return null; if (!state.layout_valid) return null; const page = @min(at.page, state.page_count -| 1); return @as(f64, @floatFromInt(state.page_starts[page])) + @@ -3069,7 +3073,7 @@ pub fn placeY(pane: *const pardes.Pane, at: Place) ?f64 { /// reopened), it is anchored there for the first layout. pub fn landAt(core: *pardes.Pardes, pane: *pardes.Pane, at: Place) void { if (comptime !enabled) return; - const state = &(pane.pdf orelse return); + const state = pane.pdf orelse return; const page = @min(at.page, state.page_count -| 1); activatePage(core, pane, page, false); state.scroll_to_page_pending = false; @@ -3087,13 +3091,13 @@ pub fn landAt(core: *pardes.Pardes, pane: *pardes.Pane, at: Place) void { pub fn toggleFit(pane: *pardes.Pane) void { if (comptime !enabled) return; - const state = &(pane.pdf orelse return); + const state = pane.pdf orelse return; state.toggleFit(); } pub fn toggleTint(pane: *pardes.Pane) void { if (comptime !enabled) return; - const state = &(pane.pdf orelse return); + const state = pane.pdf orelse return; state.toggleTint(); } @@ -3111,7 +3115,7 @@ pub fn paneViewport(core: *const pardes.Pardes, pane: *const pardes.Pane) ?Viewp pub fn ensurePaneLayout(core: *pardes.Pardes, pane: *pardes.Pane) ?Viewport { if (comptime !enabled) return null; - const state = &(pane.pdf orelse return null); + const state = pane.pdf orelse return null; const view = paneViewport(core, pane) orelse return null; ensureLayout(state, view); return view; @@ -3128,7 +3132,7 @@ pub fn tintColors(core: *const pardes.Pardes) TintColors { pub fn paneGeometry(core: *const pardes.Pardes, pane: *const pardes.Pane) ?image.NativeGeometry { if (comptime !enabled) return null; - const state = if (pane.pdf) |*view| view else return null; + const state = if (pane.pdf) |view| view else return null; const view = paneViewport(core, pane) orelse return null; return activeGeometry(state, view); } @@ -3136,7 +3140,7 @@ pub fn paneGeometry(core: *const pardes.Pardes, pane: *const pardes.Pane) ?image /// The page under grid row `row`, from the middle of its cell. pub fn pageAtGridRow(core: *const pardes.Pardes, pane: *const pardes.Pane, row: u16) ?usize { if (comptime !enabled) return null; - const state = &(pane.pdf orelse return null); + const state = pane.pdf orelse return null; const rect = core.rects[core.paneIdOf(pane) orelse return null]; const body_y = core.bodyTop(pane, rect); if (!state.layout_valid or row < body_y or row >= body_y + (rect.h -| pane.tag_rows)) return null; @@ -3154,7 +3158,7 @@ pub fn pageAtGridRow(core: *const pardes.Pardes, pane: *const pardes.Pane, row: pub fn paneNativeReady(core: *const pardes.Pardes, pane: *const pardes.Pane) bool { if (comptime !enabled) return false; if (!core.native_images) return false; - const state = if (pane.pdf) |*view| view else return false; + const state = if (pane.pdf) |view| view else return false; const view = paneViewport(core, pane) orelse return false; for (state.rasters[0..state.rasters_len]) |*raster| { if (raster.valid and raster.rgba.len > 0 and @@ -3170,7 +3174,7 @@ pub fn nativePageAtGridRow( ) ?usize { if (comptime !enabled) return null; if (!core.native_images) return null; - const state = if (pane.pdf) |*view| view else return null; + const state = if (pane.pdf) |view| view else return null; const page = pageAtGridRow(core, pane, row) orelse return null; const view = paneViewport(core, pane) orelse return null; if (!pageReady(state, view, page)) return null; @@ -3188,7 +3192,7 @@ pub fn panePointAtPage( clamp_to_page: bool, ) ?Point { if (comptime !enabled) return null; - const state = if (pane.pdf) |*view| view else return null; + const state = if (pane.pdf) |view| view else return null; const view = paneViewport(core, pane) orelse return null; const raster = rasterForPageConst(state, page) orelse return null; if (raster.rgba.len == 0) return null; @@ -3210,7 +3214,7 @@ pub fn probeAt( if (comptime !enabled) return null; const page = nativePageAtGridRow(core, pane, row) orelse return null; const point = panePointAtPage(core, pane, page, col, row, false) orelse return null; - const state = &(pane.pdf orelse return null); + const state = pane.pdf orelse return null; if (state.document.linkAt(core.pdf_gpa, page, point) catch null) |found| { var link = found; if (look.pdfLinkLocation(core, pane, link) != null) { @@ -3241,7 +3245,7 @@ pub fn beginDrag( if (comptime !enabled) return false; const hit_page = pageAtGridRow(core, pane, row) orelse return false; if (hit_page != pane.pdf.?.page) activatePage(core, pane, hit_page, false); - const state = &pane.pdf.?; + const state = pane.pdf.?; state.clearDrag(); const point = panePointAtPage(core, pane, state.page, col, row, false) orelse return false; state.drag_anchor = point; @@ -3265,7 +3269,7 @@ pub fn updateSelection( invalidate_raster: bool, ) SelectionUpdate { if (comptime !enabled) return .failed; - const state = &(pane.pdf orelse return .failed); + const state = pane.pdf orelse return .failed; const anchor = state.drag_anchor orelse return .failed; const point = panePointAtPage(core, pane, state.page, col, row, true) orelse return .failed; if (state.drag_head) |head| if (head.x == point.x and head.y == point.y) return .stationary; @@ -3335,7 +3339,7 @@ pub fn pointerUpdate( pub fn pointerCancel(pane: *pardes.Pane, drag: PointerDrag) void { if (comptime !enabled) return; - if (drag.native) if (pane.pdf) |*state| { + if (drag.native) if (pane.pdf) |state| { if (drag.selection_changed) state.invalidateRaster(state.page); state.clearDrag(); }; @@ -3349,7 +3353,7 @@ pub fn pointerRelease( chorded: bool, ) PointerRelease { if (comptime !enabled) return .{}; - const state = &(pane.pdf orelse return .{}); + const state = pane.pdf orelse return .{}; const slot = @backingInt(button); const grid_selection = pane.sel[slot]; pane.sel[slot].state = .none; // native quads, not projected text cells @@ -3427,7 +3431,7 @@ pub fn scrollPane(core: *pardes.Pardes, pane: *pardes.Pane, delta_pixels: f64, g if (comptime !enabled) return false; const tz = tracy.zone(@src(), "pdf.scroll_notch"); defer tz.end(); - const state = &(pane.pdf orelse return false); + const state = pane.pdf orelse return false; const view = ensurePaneLayout(core, pane) orelse return false; const from = state.document_scroll_y; const result = scrollDocument(state, view, delta_pixels) orelse return false; @@ -3461,7 +3465,7 @@ fn stripAt(state: *State, view: Viewport, motion: pardes.animation.Motion, now_n /// A PDF strip is still on its way to where the core stands. pub fn moving(core: *const pardes.Pardes) bool { if (comptime !enabled) return false; - for (core.panes) |slot| if (slot) |pane| if (pane.pdf) |*state| if (state.follow.moving()) return true; + for (core.panes) |slot| if (slot) |pane| if (pane.pdf) |state| if (state.follow.moving()) return true; return false; } @@ -3469,7 +3473,7 @@ pub fn verticalWheel(core: *pardes.Pardes, pane: *pardes.Pane, direction: i8) vo if (comptime !enabled) return; if (!core.native_images) { // The text layer: a page a notch. - const state = &(pane.pdf orelse return); + const state = pane.pdf orelse return; if (stepPage(state, core.pdf_gpa, direction)) resetPageChrome(pane); return; } @@ -3480,7 +3484,7 @@ pub fn verticalWheel(core: *pardes.Pardes, pane: *pardes.Pane, direction: i8) vo pub fn horizontalWheel(core: *pardes.Pardes, pane: *pardes.Pane, direction: i8) void { if (comptime !enabled) return; - const state = &(pane.pdf orelse return); + const state = pane.pdf orelse return; if (!core.native_images or state.fit != .height) return; const placed = paneGeometry(core, pane) orelse return; const cols: u32 = @intCast(@max(1, config.wheel_cols)); @@ -3499,7 +3503,7 @@ pub fn draw( ) bool { if (comptime !enabled) return false; if (!core.native_images or rect.h <= pane.tag_rows) return false; - const state = &(pane.pdf orelse return false); + const state = pane.pdf orelse return false; const view = paneViewport(core, pane) orelse return false; const key = TintKey{ .mode = state.tint, .colors = tintColors(core) }; applySizes(state, core.pdf_gpa); diff --git a/src/tagline.zig b/src/tagline.zig index 73683c1e..e7194981 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -113,7 +113,7 @@ fn shownDir(arena: std.mem.Allocator, pane: *Pane) ![]const u8 { /// PDF's page, a terminal's directory -- without the space that parts it /// from the tag's own text. It is never stored, and never edited. pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 { - if (comptime pdf_enabled) if (pane.pdf) |*pv| + if (comptime pdf_enabled) if (pane.pdf) |pv| return std.fmt.allocPrint(arena, "{s} [{d}/{d}]", .{ pv.path, pv.page + 1, pv.page_count }); // What is drawn: with no graphics, glyph art whatever `Petscii` says. if (pane.image) |*state| return panes.Image.tagPrefix(arena, state, state.glyph_art or !p.native_images); diff --git a/test/pdf.zig b/test/pdf.zig index 9e183224..655e046a 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -369,7 +369,7 @@ test "watched PDF reload replaces MuPDF state and preserves the reading view" { try std.testing.expect(watched); const pane = p.panes[0].?; - const state = &pane.pdf.?; + const state = pane.pdf.?; try std.testing.expectEqual(@as(usize, 3), state.page_count); panes.Pdf.openSections(p, 0); const sections_id = pane.search_pane orelse return error.MissingPdfSectionsOutput; @@ -495,7 +495,7 @@ test "PDF reload does not re-center an already revealed matching search" { defer p.deinit(); p.native_images = true; const pane = p.panes[0].?; - const state = &pane.pdf.?; + const state = pane.pdf.?; try state.setSearchQuery(p.pdf_gpa, "Pardes"); var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); @@ -578,7 +578,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { try std.testing.expectEqual(pdf_raster_policy.max_dimension, request.max_dimension); try std.testing.expectEqual( request, - panes.Pdf.rasterForPage(&pane.pdf.?, pane.pdf.?.page).?.request, + panes.Pdf.rasterForPage(pane.pdf.?, pane.pdf.?.page).?.request, ); try std.testing.expect(@max(first_place.iw, first_place.ih) <= request.max_dimension); if (pdf_raster_policy.match_viewport) { @@ -611,7 +611,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { try std.testing.expectEqual(@as(f64, p.cell_pixels.h), pane.pdf.?.document_scroll_y); try std.testing.expectEqual( first_place.native.revision, - panes.Pdf.rasterForPage(&pane.pdf.?, pane.pdf.?.page).?.revision, + panes.Pdf.rasterForPage(pane.pdf.?, pane.pdf.?.page).?.revision, ); _ = frame.reset(.retain_capacity); const panned = try p.render(frame.allocator()); @@ -671,7 +671,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { try std.testing.expectEqual(@max(@as(f64, 0), counted_full - @as(f64, @floatFromInt(key_viewport.pixel_h * 2))), pane.pdf.?.document_scroll_y); try std.testing.expectEqual( first_place.native.revision, - panes.Pdf.rasterForPage(&pane.pdf.?, pane.pdf.?.page).?.revision, + panes.Pdf.rasterForPage(pane.pdf.?, pane.pdf.?.page).?.revision, ); // At a page boundary both page rasters coexist, the gap remains uncovered, @@ -712,13 +712,13 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { pane.pdf.?.document_scroll_y = @as(f64, @floatFromInt(pane.pdf.?.page_starts[1])) - 0.5; try std.testing.expectEqual( page0_revision, - panes.Pdf.rasterForPage(&pane.pdf.?, 0).?.revision, + panes.Pdf.rasterForPage(pane.pdf.?, 0).?.revision, ); try std.testing.expect(panes.Pdf.scrollPane(p, pane, 1, false)); try std.testing.expectEqual(@as(usize, 1), pane.pdf.?.page); try std.testing.expectEqual( page1_revision, - panes.Pdf.rasterForPage(&pane.pdf.?, pane.pdf.?.page).?.revision, + panes.Pdf.rasterForPage(pane.pdf.?, pane.pdf.?.page).?.revision, ); panes.Pdf.activatePage(p, pane, 0, false); pane.pdf.?.document_scroll_y = before_boundary_scroll; @@ -745,7 +745,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { try std.testing.expect(away.images.items.len > 0); for (away.images.items) |place| try std.testing.expect(place.native.page != 0); - try std.testing.expect(panes.Pdf.rasterForPage(&pane.pdf.?, 0) == null); + try std.testing.expect(panes.Pdf.rasterForPage(pane.pdf.?, 0) == null); try std.testing.expectEqual(@as(usize, 1), pane.pdf.?.spare_len); const retired = pane.pdf.?.spare[0]; panes.Pdf.activatePage(p, pane, 0, true); @@ -761,7 +761,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { const fit_builtin = std.meta.stringToEnum(Builtin, "PdfFit") orelse return error.MissingPdfFitBuiltin; const revision_before_toggle = panes.Pdf.rasterForPage( - &pane.pdf.?, + pane.pdf.?, pane.pdf.?.page, ).?.revision; try std.testing.expect(pardes.test_api.runBuiltin( @@ -776,7 +776,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { try std.testing.expectEqual(@as(u16, 0), pane.pdf.?.pan_y); try std.testing.expectEqual( revision_before_toggle, - panes.Pdf.rasterForPage(&pane.pdf.?, pane.pdf.?.page).?.revision, + panes.Pdf.rasterForPage(pane.pdf.?, pane.pdf.?.page).?.revision, ); const height_tag = try pardes.tagline.tagText(p, p.scratch.allocator(), pane); const expected_height_tag = try std.fmt.allocPrint(p.scratch.allocator(), "{s} [{d}/{d}]{s}", .{ pane.pdf.?.path, pane.pdf.?.page + 1, pane.pdf.?.page_count, pane_tail }); @@ -792,7 +792,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { // A fit-height landscape page exposes horizontal overflow to a horizontal // wheel without rerasterizing. Use synthetic dimensions only for the // geometry check; no frame is drawn while they differ from the buffer. - const active_raster = panes.Pdf.rasterForPage(&pane.pdf.?, pane.pdf.?.page).?; + const active_raster = panes.Pdf.rasterForPage(pane.pdf.?, pane.pdf.?.page).?; const saved_iw = active_raster.iw; const saved_ih = active_raster.ih; active_raster.iw = 2000; @@ -893,7 +893,7 @@ test "a fling's banded pages show the reader exactly what whole pages would" { defer p.deinit(); p.native_images = true; const pane = p.panes[0].?; - const pv = &pane.pdf.?; + const pv = pane.pdf.?; var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); _ = try p.render(frame.allocator()); @@ -997,7 +997,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh defer p.deinit(); p.native_images = true; const pane = p.panes[0].?; - const pv = &pane.pdf.?; + const pv = pane.pdf.?; var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); _ = try p.render(frame.allocator()); @@ -1155,7 +1155,7 @@ test "Escape cancels PDF chrome in place, then leaves the pane; Shift-Escape lea }); defer p.deinit(); const pane = p.panes[0].?; - const pv = &pane.pdf.?; + const pv = pane.pdf.?; p.native_images = true; // A second pane, then focus it and come back: `Last` has somewhere to go @@ -1236,7 +1236,7 @@ test "PDF continuous strip renders every intersecting short page" { }); defer p.deinit(); const pane = p.panes[0].?; - const pv = &pane.pdf.?; + const pv = pane.pdf.?; try std.testing.expect(pv.page_count > 3); p.native_images = true; @@ -1312,7 +1312,7 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" { defer p.deinit(); p.settings.motion = .off; // placements, not the glide (anim 11) const pane = p.panes[0].?; - const pv = &pane.pdf.?; + const pv = pane.pdf.?; p.native_images = true; var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); @@ -1451,7 +1451,7 @@ test "PDF resize preserves page-relative document position" { }); defer p.deinit(); const pane = p.panes[0].?; - const pv = &pane.pdf.?; + const pv = pane.pdf.?; p.native_images = true; var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); @@ -1502,7 +1502,7 @@ test "PDF pane geometry change preserves its page-relative position" { _ = layout.splitColumn(p, 0, 1, false); p.sync(); // rects for the new column, exactly as the two-pane boot did const pane = p.panes[0].?; - const pv = &pane.pdf.?; + const pv = pane.pdf.?; p.native_images = true; var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); @@ -1554,7 +1554,7 @@ test "PDF n/N addresses and reveals distinct MuPDF hits on one page" { }); defer p.deinit(); const pane = p.panes[0].?; - const pv = &pane.pdf.?; + const pv = pane.pdf.?; p.native_images = true; var page_hits = try pv.document.search(gpa, 0, "Pardes"); @@ -1685,7 +1685,7 @@ test "PDF native mouse selection, Look, and highlights share page geometry" { const quad = found.quads[0].quad; const nx = (quad.ul.x + quad.ur.x + quad.ll.x + quad.lr.x) / 4; const ny = (quad.ul.y + quad.ur.y + quad.ll.y + quad.lr.y) / 4; - const pv = &pane.pdf.?; + const pv = pane.pdf.?; const raster = panes.Pdf.rasterForPage(pv, pv.page).?; const source_x: u32 = @intCast(@min( raster.iw - 1, @@ -2020,7 +2020,7 @@ test "Esc back into a PDF keeps the offset within its page" { p.sync(); // Read a little way DOWN the page you are on, then step away. - const pv = &dp.pdf.?; + const pv = dp.pdf.?; pv.document_scroll_y += 137; const mid = pv.document_scroll_y; pv.scroll_to_page_pending = false; @@ -2049,7 +2049,7 @@ test "PDF Back and Forward clear selections and land on recorded pages" { p.native_images = true; p.presentation.enabled = false; const pane = p.panes[0].?; - const state = &pane.pdf.?; + const state = pane.pdf.?; try std.testing.expect(state.page_count > 1); try std.testing.expect(state.focusLocation(p.pdf_gpa, 2, 0)); p.njumps = 2; @@ -2091,7 +2091,7 @@ test "a PDF's fit and tint, and Collapse, read in its ctl and come back from a D try pardes.dump.dumpState(p); const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon"); defer restored.deinit(); - const pv = &restored.panes[0].?.pdf.?; + const pv = restored.panes[0].?.pdf.?; try std.testing.expectEqualStrings("height", @tagName(pv.fit)); try std.testing.expectEqualStrings("full", @tagName(pv.tint)); } @@ -2114,7 +2114,7 @@ fn jumpFrame(p: *Pardes) !void { } fn stripAtPlace(p: *Pardes, pane: *pardes.Pane, page: usize, fraction: f64) !f64 { - const pv = &pane.pdf.?; + const pv = pane.pdf.?; pv.document_scroll_y = @as(f64, @floatFromInt(pv.page_starts[page])) + fraction * @as(f64, @floatFromInt(pv.page_heights[page])); try jumpFrame(p); return pv.document_scroll_y; @@ -2128,7 +2128,7 @@ test "a PDF's jumps: Back after a far jump returns to the exact offset, two plac p.presentation.enabled = false; const id = p.active; const pane = p.panes[id].?; - const pv = &pane.pdf.?; + const pv = pane.pdf.?; try jumpFrame(p); try std.testing.expect(pv.page_count > 3); // Two places on page 1, more than a body apart: two entries. @@ -2199,7 +2199,7 @@ test "a PDF's jumps: JumpScope file keeps to the PDF, and a closed PDF reopens a } const reopened = p.panes[p.active].?; try std.testing.expect(reopened.pdf != null); - const pv = &reopened.pdf.?; + const pv = reopened.pdf.?; // The newest PDF place before the text: page 4, half way down. try std.testing.expectEqual(@as(usize, 3), pv.page); const want = @as(f64, @floatFromInt(pv.page_starts[3])) + 0.5 * @as(f64, @floatFromInt(pv.page_heights[3])); diff --git a/test/pdf_pointer_bench.zig b/test/pdf_pointer_bench.zig index a6560263..573b8766 100644 --- a/test/pdf_pointer_bench.zig +++ b/test/pdf_pointer_bench.zig @@ -124,7 +124,7 @@ var verify_failures: usize = 0; fn verify(core: *pardes.Pardes, arena: std.mem.Allocator) !void { const Pdf = pardes.panes.Pdf; const pane = core.panes[0] orelse return; - const state = &(pane.pdf orelse return); + const state = pane.pdf orelse return; const highlights = try Pdf.buildHighlights(state, arena, Pdf.highlightInput(core, 0, pane)); for (state.rasters[0..state.rasters_len]) |*r| { if (!r.valid or r.rgba.len == 0 or r.tint_key == null) continue; diff --git a/test/pdf_scroll_bench.zig b/test/pdf_scroll_bench.zig index 391a98e6..1a27b828 100644 --- a/test/pdf_scroll_bench.zig +++ b/test/pdf_scroll_bench.zig @@ -263,7 +263,7 @@ fn probeTravel(config: Config) Travel { const first_frame_ns = nowNs() -| started; const pane = core.panes[0] orelse fatal("PDF pane disappeared", .{}); if (pane.pdf == null) fatal("{s} did not open as a PDF", .{path}); - const pv = &pane.pdf.?; + const pv = pane.pdf.?; if (!pv.layout_valid or pv.document_height == 0) fatal("the pixel strip never laid out; is native_images/cell_pixels wired?", .{}); // Exactly the clamp scrollPdfDocument enforces, so the last fling frame @@ -356,7 +356,7 @@ fn measure(config: Config, plan: Plan) !Result { _ = try core.render(frame_arena.allocator()); drainEffects(core); const pane = core.panes[0] orelse fatal("PDF pane disappeared", .{}); - const pv = &pane.pdf.?; + const pv = pane.pdf.?; const rect = core.rects[0]; // Anywhere inside the pane body resolves to this pane's hover, which // is what routes the notch; the exact cell is irrelevant to a wheel. diff --git a/test/pdf_sections_bench.zig b/test/pdf_sections_bench.zig index b793bd0c..4d0f85de 100644 --- a/test/pdf_sections_bench.zig +++ b/test/pdf_sections_bench.zig @@ -335,7 +335,7 @@ fn sectionsOutputIdentity(core: *pardes.Pardes) Identity { fn stepIdentity(core: *pardes.Pardes) Identity { var identity = sectionsOutputIdentity(core); const owner = core.panes[0].?; - const view = &owner.pdf.?; + const view = owner.pdf.?; identity.checksum = mix(identity.checksum, view.page); identity.checksum = mix(identity.checksum, @as(u64, @bitCast(view.document_scroll_y))); identity.checksum = mix(identity.checksum, owner.search_row orelse std.math.maxInt(usize)); -- cgit v1.3