Congratsbot / check-author (push) Skipped
Congratsbot / congrats (push) Waiting for needed jobs
deploy_nightly_docs / deploy_docs (push) Skipped
run_tests / orchestrate (push) Skipped
run_tests / check_style (push) Skipped
run_tests / clippy_windows (push) Skipped
run_tests / clippy_linux (push) Skipped
run_tests / clippy_mac (push) Skipped
run_tests / clippy_mac_x86_64 (push) Skipped
run_tests / run_tests_windows (push) Skipped
run_tests / run_tests_linux (push) Skipped
run_tests / run_tests_mac (push) Skipped
run_tests / miri_scheduler (push) Skipped
run_tests / doctests (push) Skipped
run_tests / check_workspace_binaries (push) Skipped
run_tests / build_visual_tests_binary (push) Skipped
run_tests / check_wasm (push) Skipped
run_tests / check_dependencies (push) Skipped
run_tests / check_docs (push) Skipped
run_tests / check_licenses (push) Skipped
run_tests / check_scripts (push) Skipped
run_tests / check_remote_server_linux_x86_64 (push) Skipped
run_tests / check_remote_server_mac_aarch64 (push) Skipped
run_tests / check_remote_server_windows_x86_64 (push) Skipped
run_tests / check_postgres_and_protobuf_migrations (push) Skipped
run_tests / extension_tests (push) Skipped
run_tests / tests_pass (push) Skipped
The annotation and form-filling surface is being dropped, so remove it end to end rather than leave it half-maintained. pdf_viewer loses the editing APIs and everything only they used: add_ink_annotation, add_highlight_annotation, delete_annotation, apply_form_edits, the form widget and annotation extraction, the PdfFormWidget/PdfFormEdit/PdfAnnotation types, the document serialization helper, and the pdfium guards and constants those functions were the sole users of. Rendering, text, links, outline and metadata are untouched; annotation rendering stays on because it paints markup already embedded in viewed documents. image_viewer loses the tool palette, form widget overlays, inline form editors, pen canvas, option menus, the annotate toolbar button, the Undo Edit and Delete Annotation actions and their key bindings, plus the associated state and handlers. Text selection, find, links, thumbnails, outline, properties, rotation, presentation and Save a Copy remain.
pdf_viewer: Native PDF Viewer for Zed
A native, high performance PDF viewing engine and GPUI workspace item engineered for Zed.
0. Architectural Identity & Delivery Model
Important
: This is a native workspace crate, not an installable WASM extension.
As of current Zed versions, Zed's WebAssembly extension API (zed_extension_api) contains no custom UI or file preview surfaces.pdf_vieweris designed as a native crate registered within the Zed workspace (crates/pdf_viewer).
1. Core Architectural Pillars
┌──────────────────────────────────────────────────────────────────────────────────┐
│ PDF_VIEWER CORE PIPELINE │
└──────────────────────────────────────────────────────────────────────────────────┘
│
[PDF Document on Disk / Memory Buffer]
│
▼
[Thread Safe Document Handle (`document.rs`)]
│
▼
[Async Background Worker Pool (`gpui::Task` / Threads)]
│
(Zero UI Thread Blocking Rasterization)
│
▼
[Memory Budgeted LRU Cache (`cache.rs`)]
│
(Visible Viewport + 1 Page Margin)
│
▼
[Luminosity Tone Mapping Engine (`ui.rs`)]
│
(Inverts White/Black; Preserves Images)
│
▼
[Native GPUI Canvas / Bitmap Painter (`view.rs`)]
- Zero UI Thread Blocking: PDF parsing and rasterization never execute on GPUI's main render loop. Work is dispatched to background tasks that stream RGBA framebuffers into memory.
- Viewport Virtualization & LRU Caching: Pages are rasterized on demand for the visible viewport plus a 1 page prefetch margin. Stale or passed by in flight render requests are cancelled during fast scrolls to prevent thread pool starvation.
- Luminosity Threshold Dark Mode: Unlike simple blanket RGB inversion (which turns photos and charts into negative ghosts),
pdf_viewerimplements selective tone mapping, remapping near white canvas backgrounds to editor background tones and near black text to theme light text, while preserving saturated color images. - Scroll & Zoom Preserving Live Reload: Watches the underlying PDF on disk (via file system notifications) and reloads seamlessly without resetting the user's scroll percentage or zoom level.
2. Scope Boundaries
- Continuous Scroll & Text Selection: Supports fluid high frame rate document browsing and visual text selection.
- Excluded from scope:
- Interactive PDF form field editing.
- Annotation authoring, editing and deletion.
- Rationale: Delivering an ultra fast, stutter free viewing experience with zero UI locks takes precedence.
3. Security Posture & Threat Model
- In Process Parsing: PDF rasterization is performed via Google's native C++ Pdfium engine linked in process with the editor.
- Accepted Risk: Because Pdfium runs in process without sandboxing (for example, without separate process IPC or WebAssembly memory isolation), malformed or malicious PDFs could theoretically trigger memory vulnerabilities in the underlying C++ library.
- Mitigation & Future Hardening: Memory budgets are strictly capped, document handles are isolated behind thread boundaries, and a future sandboxed worker process model is planned for untrusted file browsing.
4. Repository Layout
crates/pdf_viewer/
├── Cargo.toml # Native crate manifest
├── README.md # Architecture & operational guide
├── tests/
│ └── integration_tests.rs # End to end integration tests
└── src/
├── pdf_viewer.rs # Crate entrypoint & exports
├── cache.rs # Memory budgeted generic PageLruCache
├── document.rs # Thread safe PdfDocument handle
├── pdfium.rs # Pdfium engine binding & coordinate normalization
├── rasterizer.rs # Async background rendering pipeline
├── settings.rs # PDF viewer configuration options
├── ui.rs # Toolbar state & action models
├── view.rs # GPUI Render & Workspace Item implementation
└── watcher.rs # Live reload file watcher & scroll state
5. Local Development & Testing
Run unit and integration tests across the caching and rasterization engines:
cargo test -p pdf_viewer