Write notes beside a PDF

Stage six. What you write goes into the note's ordinary content, so it is
encrypted, versioned, linkable and searchable like any other note — a PDF
note is a note with a document attached, not a separate kind of thing.

The panel is composed from the editor pieces rather than reusing
NoteEditor, which carries a whole drawing mode with its own canvas, tools
and undo stack. The PDF already has a drawing layer; a second one behind
the panel would be two places to draw with one of them invisible.

Side by side on a wide screen, two tabs on a narrow one, and either half
can be hidden — the second of the two toggles asked for. Reading the
original without one's own marks in the way is a normal thing to want.

The suite caught a real defect while checking this. A PDF note has two
sources of searchable text — what the reader typed and what the document
says — written at different moments by different code, both calling
setEntry. Whichever ran last was the only searchable half: typing a note
dropped the document's text, and reopening the document dropped the note.
The index now holds the two apart and replaces only the half it is given,
with six unit tests covering each direction, plus the snippet falling back
to the document so a hit inside a PDF still shows its sentence.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
marcandClaude Opus 5 committed 2026-08-08 21:29:39 +02:00
1 parent b12b0d6142
commit 7f9f39790f
8 files changed
+409 -16

No files matched your search

+27 -2
View File
@@ -17,7 +17,7 @@ A self-hosted note-taking application with rich text editing, freehand drawing,
- **Undo/Redo** — Full history stack for drawing operations
- **Notebooks & Folders** — Create notebooks with custom gradient covers, organize notes by folder
- **Star/Favorite** — Quick access to important notes
- **PDF Reading** — Import a PDF, read it, select its text, draw on it; the file is cached so it stays readable offline
- **PDF Reading** — Import a PDF, read it, select its text, draw on it and write notes beside it; the file is cached so it stays readable offline
- **Export** — Any note, notebook or the whole account as Markdown or PDF, entirely in the browser
- **Dark & Light Mode** — Full theme support with refined color schemes
@@ -330,7 +330,7 @@ docker compose -f docker-compose.dev.yml up -d --build # must be running
| `search-attachments` | 12 | body-only matches, ranking, umlauts; images as blob URLs, not inline bytes |
| `history` | 10 | a large deletion is snapshotted, restoring works, restoring is itself undoable |
| `drawing` | 7 | strokes survive the poller, and match across four viewport widths |
| `pdf` | 26 | import, page proportions, lazy loading, and reading with the network off |
| `pdf` | 32 | import, page proportions, lazy loading, and reading with the network off |
| `conflict` | 10 | a late write wins but the state it buries survives as a version |
| `export` | 21 | the downloaded bytes are real Markdown, ZIP and PNG, unpacked and read back |
@@ -442,6 +442,31 @@ storage is content-addressed, a cached copy can never go stale.
---
## Notes beside a PDF
A PDF note is a note that happens to have a document attached, not a separate
kind of thing: what you write beside it goes into the note's ordinary `content`,
so it is encrypted, versioned, linkable and searchable like any other note.
The panel is composed from the editor pieces directly rather than reusing
`NoteEditor`, which carries a whole drawing mode with its own canvas and undo
stack — the PDF has its own drawing layer, and a second one hidden behind the
panel would be two places to draw with one of them invisible.
Side by side on a wide screen, two tabs on a narrow one. Both halves can be
hidden: reading the original without one's own marks in the way is a normal
thing to want, and so is writing without the document taking two thirds of the
screen.
**One trap this uncovered.** A PDF note has two sources of searchable text —
what the reader typed and what the document says — written at different moments
by different code. Both called `setEntry`, so whichever ran last was the only
half you could search: typing a note dropped the document's text, and re-reading
the document dropped the note. The index now keeps them apart and only replaces
the half it was given.
---
## Selecting and searching PDF text
pdf.js draws pages as pictures, so selecting means laying transparent spans over