diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-31 06:28:48 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-31 06:28:48 -0300 |
| commit | a479792a1ab2b593642d7f648194bfa23ce01dba (patch) | |
| tree | 96ddee7d879a9084daa07db43b0b7910b072a785 /src/pdf_view.zig | |
| parent | e179cc44fe5060c76a5b00c41e53f11209f5acd9 (diff) | |
| parent | 4c761893e5b3fdae422622cfa02104ab36633045 (diff) | |
| download | pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.tar.gz pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.zip | |
Merge the upstream daemon and replicated client/server refactor
Diffstat (limited to 'src/pdf_view.zig')
| -rw-r--r-- | src/pdf_view.zig | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/pdf_view.zig b/src/pdf_view.zig index f6d26eac..0745a6fc 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -84,6 +84,7 @@ pub const TintKey = if (enabled) struct { pub const Highlight = if (enabled) pdf.Highlight else void; pub const Highlights = if (enabled) struct { const Page = struct { page: usize, items: []const Highlight }; + pub const replica = .{ .len = .{.{ "pages", "len" }} }; pages: [3]Page = undefined, len: usize = 0, /// Repaint whenever the set changes, not only when a page's raster was @@ -619,6 +620,9 @@ pub const SectionsOutput = if (enabled) struct { pub const SelectionUpdate = enum { failed, stationary, unchanged, changed }; pub const State = if (enabled) struct { + /// What the replay digest leaves out (src/walk.zig): the pages' pixels, + /// rendered from the document, and the lanes rendering them. + pub const replica = .{ .derived = .{ "rasters", "rasters_len" }, .local = .{"lanes"} }; path: []u8, document: Document, page: usize = 0, @@ -902,12 +906,15 @@ pub const State = if (enabled) struct { if (page) |selected_page| state.invalidateRaster(selected_page); } - pub fn cancelChrome(state: *@This(), gpa: std.mem.Allocator) void { + /// Drops the selection and the search; true when there was one. + pub fn cancelChrome(state: *@This(), gpa: std.mem.Allocator) bool { + const had = state.selection != null or state.search_query.len > 0; state.clearDrag(); state.clearSelection(gpa); - if (state.search_query.len == 0) return; + if (state.search_query.len == 0) return had; state.dropSearchQuery(gpa); state.invalidateRaster(state.page); + return had; } fn invalidatePage(state: *@This(), gpa: std.mem.Allocator) void { @@ -1226,6 +1233,7 @@ pub const ScrollResult = struct { active_page: usize }; pub const CellPixels = struct { w: u16, h: u16 }; pub const NormalHost = enum { none, + last, leader, command_line, search, @@ -2472,7 +2480,11 @@ pub fn applyNormal( if (comptime !enabled) return .{}; var result: NormalResult = .{}; switch (semantic) { - .escape => state.cancelChrome(gpa), + // Esc drops a selection or a search the page shows, else goes back + // a pane (text-only, the page shows neither). + .escape => if (!state.cancelChrome(gpa) or !native_images) { + result.host = .last; + }, .move => |move| switch (move.motion) { .down => result.page_changed = moveRows( state, @@ -2836,6 +2848,20 @@ pub fn deinitPane(core: *pardes.Pardes, pane: *pardes.Pane, state: *State) void state.deinit(core.pdf_gpa); } +/// 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 local = filesystem.localPath(state.path) orelse return error.NonLocalPath; + const bytes = try filesystem.readFile(core.pdf_gpa, local); + defer core.pdf_gpa.free(bytes); + state.document = try Document.openBytes(bytes); + if (state.document.pages != state.page_count or fileKey(state.path, bytes) != state.file) { + try state.reload(core.pdf_gpa); + } +} + pub fn reloadPane( core: *pardes.Pardes, pane: *pardes.Pane, |
