Skip to content

Preview PDFs in the Files pane and reopen them on the same page and zoom after a thread switch - #1995

Merged
currentbits merged 2 commits into
mainfrom
coder/pdf-preview-1938
Nov 11, 2026
Merged

currentbits merged 2 commits into
mainfrom
coder/pdf-preview-1938

Conversation

@currentbits

Copy link
Copy Markdown
Owner

PDFs in the Files pane used to show "Binary file, no preview." Now they open in a page-by-page viewer, and switching threads and back reopens the same file on the same page and zoom. Closes #1938.

Changes

  • files:read returns a new pdf kind with the file's bytes (32 MB cap; text stays at 1 MB, images at 8 MB).
  • New viewer: one page at a time on a canvas, prev/next, zoom steps, fit width, keyboard (←/→, PageUp/PageDown, Home/End, +/−). pdf.js loads lazily and parses in its own worker; the preview owns its document + worker and destroys both on close. No shared worker or cross-mount document cache, per the issue's "only after profiling" note.
  • The pane is keyed per thread, so each thread's open file and each PDF's page/zoom live in a bounded module-level LRU (50 threads × 20 PDFs). A page past the end of a shrunk file is clamped; a deleted file is forgotten. Unopenable files show "Could not open this PDF: …". Attachment PDF text extraction (electron/pdf-text.js) is untouched.

Verification

  • npm run test:renderer: 3964 pass. New cases cover paging/zoom, restore after a thread switch, clamping, deleted-file forgetting, open errors and the 32 MB message. Breaking the memory on purpose makes the thread-switch test fail.
  • electron/test/files-pane.test.js: 7 pass (pdf bytes past 1 MB, 32 MB cap).
  • npm run typecheck, npx vite build clean; the pdf.js worker ships as its own lazy asset.
  • Real pdf.js in Chromium (vite dev) drew page 2 of a generated 2-page PDF correctly; garbage bytes → "Invalid PDF structure.".
  • In Electron with loadFile + the production CSP, pdf.js's module worker loads from file:// and answers ready, so parsing really runs off the UI thread.
  • Not tested: a full packaged app run; large PDFs over the web/remote transport.

Notes for reviewers

  • Bytes travel as base64 (works over the JSON web transport). A ~32 MB PDF means a ~43 MB string and an atob decode on open; I estimate a 100–200 ms hitch but didn't measure it.
  • No cMap/standard-font/wasm assets are shipped, so CJK cmaps, unembedded base-14 fonts and JPX images may display poorly.
  • Fit width is worked out once on open; the remembered state doesn't survive an app restart.

claude-opus-5-5 via Claude Code

🤖 Generated with Claude Code

…read switches (#1938)

PDFs get a 'pdf' preview kind (32 MB cap) rendered one page at a time by a
lazily loaded pdf.js whose worker belongs to the open preview. The pane
remembers each thread's open file and each PDF's page/zoom in a bounded LRU,
clamps pages when a file shrinks and forgets deleted files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T10:10:51.597106Z fa59ca5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@currentbits
currentbits merged commit b61cdb0 into main Nov 11, 2026
13 of 14 checks passed
@currentbits
currentbits deleted the coder/pdf-preview-1938 branch November 11, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Built-in PDF preview with remembered page and zoom

1 participant