I'll add a marking (highlight) feature: users can select text, pick a color, and save highlights that persist across sessions per document. They can view, jump to, and delete marks from a new sidebar tab.
Let me start with the annotations library — types, coordinate conversion (rotation- and zoom-safe via PDF space), and localStorage persistence.
Now the floating color-picker popover that appears when text is selected, and a couple of new icons.
Now update PdfPage.tsx to (a) render highlight overlays under the text layer using the current viewport, and (b) emit selections upward.
Now update DocumentView to forward the new annotation props to PdfPage.
The third edit seems to have duplicated something. Let me check the current state of DocumentView.
DocumentView is fine now — only App needs updating to pass the new props. Now update Sidebar.tsx to add a "Marks" tab.
All the underlying pieces are in place. Now wire up App.tsx to hold annotation state, show the highlight popover on selection, and pass everything through. Let me view a few key parts of App.tsx first.
Let me look at the block around the Sidebar and DocumentView usage to make targeted edits.
Given the number of changes needed in App.tsx, I'll rewrite it cleanly to incorporate the annotation feature.
I need to add the marks button to the Toolbar. Let me update it.
Let me clean up the unused HighlightIcon import in App.tsx.
Now let me build to confirm everything compiles.
Build succeeded. Here's the marking feature I added:
How it works
- Select any text on a page. A floating popover appears above the selection with 5 highlight colors, a Copy button, and a dismiss button.
- Click a color → the passage is highlighted immediately, saved to
localStorage, and briefly focus-ringed. A subtle toast confirms.
- Click an existing highlight on the page → the sidebar opens to the Marks tab with that highlight scrolled into focus.
- Sidebar → Marks tab lists every mark with a color pill, page number, and the quoted text. Click to jump; hover to reveal a trash icon; use Clear all to wipe them.
- Toolbar highlight icon shows a live count badge and opens the Marks tab directly.
Nice details
- Rotation- and zoom-safe: rects are stored in PDF-page coordinate space (via
viewport.convertToPdfPoint) and re-projected each render via viewport.convertToViewportPoint, so highlights stay perfectly aligned when you zoom, rotate, or resize.
- Persistent across sessions: keyed by the document's pdf.js fingerprint (
pdf.fingerprints[0]), so re-opening the same PDF restores all marks. Falls back to filename+size or URL.
- Multi-line selections work: uses
range.getClientRects() to capture one rect per visible line.
- Blends with content: rects use
mix-blend-mode: multiply so text underneath stays readable through the color.
- Text selection still works on top of highlights (the overlay sits under the text layer with
pointer-events: none except on the highlight rects themselves).
- Keyboard shortcut: with text selected, press
h to instantly apply a yellow highlight. Esc cancels the popover.
- Sidebar auto-dismiss: the popover fades away on scroll to avoid stale positioning.
Try it out — select any text and pick a color. Your marks will be there next time you open the same PDF.
Files built: src/lib/annotations.ts, src/hooks/useAnnotations.ts, src/components/Icons.tsx, src/components/HighlightPopover.tsx, src/components/PdfPage.tsx, src/components/DocumentView.tsx, src/components/Sidebar.tsx, src/App.tsx, src/components/Toolbar.tsx