Switch "Copy Link to Highlight" to use custom highlight rendering + beginnings of annotations support#1548
Draft
cdrini wants to merge 15 commits into
Draft
Switch "Copy Link to Highlight" to use custom highlight rendering + beginnings of annotations support#1548cdrini wants to merge 15 commits into
cdrini wants to merge 15 commits into
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.08% -3.72%
==========================================
Files 67 67
Lines 5853 6103 +250
Branches 1276 1330 +54
==========================================
- Hits 3851 3789 -62
- Misses 1968 2272 +304
- Partials 34 42 +8 ☔ 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.
Comment on lines
+61
to
+63
| const selectedElement = window.getSelection()?.anchorNode; | ||
| if (selectedElement.classList.contains('BRhighlight')) { | ||
| this.getHighlightedNodes(selectedElement); |
| } | ||
|
|
||
| if (selectEvent == 'cleared') { | ||
| console.log("detected cleared event"); |
Comment on lines
110
to
+125
| renderSelectionMenu() { | ||
| if (document.querySelector('.br-select-menu__option')) return; | ||
| document.body.append(this.selectMenu); | ||
| this.selectMenu.copyHighlightEnabled = true; | ||
| if (this.highlightAnnotationEnabled) { | ||
| this.selectMenu.requestUpdate(); | ||
| } else { | ||
| document.body.append(this.selectMenu); | ||
| } | ||
| } | ||
|
|
||
| renderHighlightMenu() { | ||
| this.selectMenu.highlightAnnotationEnabled = true; | ||
| if (this.selectionMenuEnabled) { | ||
| this.selectMenu.requestUpdate(); | ||
| } else { | ||
| document.body.append(this.selectMenu); | ||
| } |
| <ia-icon-share class="br-select-menu__icon" aria-hidden="true"></ia-icon-share> | ||
| <button @click=${this.handleCopyLinkToHighlight} | ||
| class="br-select-menu__option"> | ||
| <ia-icon-share class="br-select-menu__icon aria-hidden="true"></ia-icon-share> |
| @@ -4,6 +4,8 @@ import { html, LitElement } from 'lit'; | |||
| import { customElement } from 'lit/decorators.js'; | |||
| import '@internetarchive/icon-share'; | |||
Comment on lines
+230
to
+231
| if (hasTargetText) { | ||
| const textLayer = pageContainerEl.querySelector('.BRtextLayer'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: