summaryrefslogtreecommitdiff
path: root/src/ninep/pane.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 12:29:43 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:16 -0300
commit549cfa40e99c3d1937b742a0dba043281c687c83 (patch)
tree51966e9ee0e49ddd87738f0f89ce52a279eb0c6f /src/ninep/pane.zig
parent54aaa0bce75e1f231d68647a9d7c0f052ed92f8e (diff)
downloadpardes-549cfa40e99c3d1937b742a0dba043281c687c83.tar.gz
pardes-549cfa40e99c3d1937b742a0dba043281c687c83.zip
A PDF's body reads the text layer of the page it shows
The body of a PDF pane read as empty. It now reads MuPDF's text extraction of the page shown, the text search and n/N already use, read-only (a write is refused, as round 22's body refusal made it). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/ninep/pane.zig')
-rw-r--r--src/ninep/pane.zig17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 9e832df6..311a2429 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -257,7 +257,7 @@ pub fn fileSize(p: *Pardes, id: usize, f: PaneFile) u64 {
const pf = &pane.fs;
return switch (f) {
// A terminal's body reads its screen and history, as text.
- .body => if (pane.file == null and pane.isTerminal()) panes.Terminal.screenTextLen(pane) else bodyOf(pane).len,
+ .body => if (pane.file == null and pane.isTerminal()) panes.Terminal.screenTextLen(pane) else if (pdfText(p, pane)) |t| t.len else bodyOf(pane).len,
.data, .xdata => bodyOf(pane).len,
.tag => tagOf(p, pane).len,
.name => nameOf(pane).len + 1,
@@ -367,6 +367,14 @@ fn readFlag(p: *Pardes, req: Req, on: bool) Reply {
return tree.stagedReply(p, req);
}
+/// The text layer of the page a PDF pane shows (MuPDF's extraction, kept
+/// 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);
+ return pv.ensureText(p.pdf_gpa);
+}
+
fn readBody(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
if (pane.file != null) {
const text = bodyOf(pane);
@@ -379,6 +387,13 @@ fn readBody(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
.len = clip(n),
} } };
}
+ // A PDF's body is its text layer, the page shown's: read-only.
+ if (pdfText(p, pane)) |text| {
+ const off = @min(req.off, text.len);
+ const out = p.fs.stage(p.gpa);
+ out.appendSlice(p.gpa, text[off..][0..@min(text.len - off, req.size)]) catch return Reply.fail(req.tag, E.NOMEM);
+ return tree.stagedReply(p, req);
+ }
if (req.handle != 0 and pane.isTerminal()) return screen.readSnapshot(p, req, pane);
const text = panes.Terminal.screenTextAlloc(pane, p.gpa) catch
return Reply.fail(req.tag, E.NOMEM);