Switch "Copy Link to Highlight" to use custom highlight rendering + beginnings of annotations support#1548
Conversation
Fix for failed test Jest test case fix
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1548 +/- ##
==========================================
- Coverage 65.79% 62.80% -3.00%
==========================================
Files 67 67
Lines 5853 6108 +255
Branches 1276 1333 +57
==========================================
- Hits 3851 3836 -15
- Misses 1968 2231 +263
- Partials 34 41 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors “Copy Link to Highlight” away from native browser text fragments toward a BookReader-specific text fragment format and custom highlight rendering, and introduces early scaffolding for private (localStorage-backed) highlights/annotations.
Changes:
- Introduces
BookReaderTextFragmentserialization/parsing plus DOM-based highlight rendering (renderHighlight) and localStorage-backed saved highlights. - Updates URL handling to parse
?text=into aBookReaderTextFragmentand render the target highlight when the relevant page becomes visible. - Adds/adjusts experiments + selection UI and reorganizes/moves tests around the new utilities.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
src/util/TextSelectionManager.js |
Adds BookReaderTextFragment, highlight rendering, BRSelectMenu changes, and localStorage highlight support. |
src/plugins/url/plugin.url.js |
Parses ?text= into targetTextFragment and renders target highlight on textLayerVisible. |
src/plugins/url/UrlPlugin.js |
Simplifies getHash() now that text fragments are no longer appended into the hash. |
src/BookReader.js |
Attempts to preserve text query param handling via BookReaderTextFragment during querystring rebuilds. |
src/plugins/plugin.text_selection.js |
Adds an API to enable the highlight/annotation menu. |
src/plugins/plugin.experiments.js |
Updates copy-link experiment metadata and adds an “annotateHighlight” experiment toggle. |
src/css/_TextSelection.scss |
Adds BR highlight styling and prevents hiding text layers containing highlights. |
src/css/_BRpages.scss |
Prevents hiding highlighted text layers during page flip animations. |
tests/jest/util/TextSelectionManager.test.js |
Moves walkBetweenNodes tests here and attempts to adapt to new fragment logic (currently skips fragment tests). |
tests/jest/plugins/plugin.text_selection.test.js |
Removes walkBetweenNodes tests now moved to util tests. |
tests/jest/plugins/url/plugin.url.test.js |
Updates mock URL plugin surface (adds parseToText). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Rename SelectionObserver event from focusChanged to changed - Decouple copy link to higlight and annotate experiments; either can be enabled for the select menu to appear
- Rename createTextFragment to BookReaderTextFragment.fromSelection - Add "Copied" confirmation text to CopyLinkToHighlight - Simplify text fragment parsing to use a single regex
Various code review refactors / fixes to #1538 . Created a separate PR so that we can keep the original for any before/after testing we might want to do.
Known issues:
Possibly related to using MARK elements instead of SPAN?