@samuelbradshaw/highlight-helper-js 0.7.3 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/highlight-helper.js +12 -7
- package/package.json +1 -1
package/highlight-helper.js
CHANGED
|
@@ -453,11 +453,12 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
453
453
|
changes: appearanceChanges.concat(boundsChanges),
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
-
if (
|
|
457
|
-
if (highlightId === activeHighlightId && appearanceChanges.length > 0) {
|
|
458
|
-
updateSelectionUi('appearance');
|
|
459
|
-
} else if (triggeredByUserAction && highlightId !== activeHighlightId) {
|
|
456
|
+
if (triggeredByUserAction && !activeHighlightId) {
|
|
460
457
|
this.activateHighlight(highlightId);
|
|
458
|
+
} else if (activeHighlightId && highlightId === activeHighlightId && appearanceChanges.length > 0) {
|
|
459
|
+
updateSelectionUi('appearance');
|
|
460
|
+
} else {
|
|
461
|
+
this.drawHighlights([highlightId]);
|
|
461
462
|
}
|
|
462
463
|
|
|
463
464
|
if (isNewHighlight) {
|
|
@@ -480,6 +481,7 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
480
481
|
const highlightRange = highlightToActivate.rangeObj.cloneRange();
|
|
481
482
|
activeHighlightId = highlightId;
|
|
482
483
|
updateSelectionUi('appearance');
|
|
484
|
+
updateSelectionUi('bounds');
|
|
483
485
|
|
|
484
486
|
// Update the selection range if needed
|
|
485
487
|
// In Android Chrome, sometimes selection handles don't show when a selection is updated programmatically, so it's best to only update the selection if needed.
|
|
@@ -914,8 +916,10 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
914
916
|
|
|
915
917
|
// Bring active highlight to the front
|
|
916
918
|
const svgHighlight = svgBackground.querySelector(`g[data-highlight-id="${activeHighlightId}"]`);
|
|
917
|
-
|
|
918
|
-
|
|
919
|
+
if (svgHighlight) {
|
|
920
|
+
svgBackground.appendChild(svgHighlight);
|
|
921
|
+
svgBackground.appendChild(svgActiveOverlay);
|
|
922
|
+
}
|
|
919
923
|
}
|
|
920
924
|
|
|
921
925
|
if (changeType === 'appearance') {
|
|
@@ -1010,7 +1014,7 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
1010
1014
|
|
|
1011
1015
|
// Prevent the range from starting or ending in an element that doesn't match the paragraph selector
|
|
1012
1016
|
if (this.annotatableContainer.contains(range.commonAncestorContainer) && (!startNode.parentElement.closest(options.paragraphSelector) || !endNode.parentElement.closest(options.paragraphSelector))) {
|
|
1013
|
-
annotatableParagraphsInRange = Array.from(this.annotatableParagraphs).filter((paragraph) => {
|
|
1017
|
+
let annotatableParagraphsInRange = Array.from(this.annotatableParagraphs).filter((paragraph) => {
|
|
1014
1018
|
const relativeStartPosition = startNode.compareDocumentPosition(paragraph);
|
|
1015
1019
|
const relativeEndPosition = endNode.compareDocumentPosition(paragraph);
|
|
1016
1020
|
return (relativeStartPosition & Node.DOCUMENT_POSITION_FOLLOWING || relativeStartPosition & Node.DOCUMENT_POSITION_CONTAINS) && (relativeEndPosition & Node.DOCUMENT_POSITION_PRECEDING || relativeEndPosition & Node.DOCUMENT_POSITION_CONTAINS);
|
|
@@ -1263,6 +1267,7 @@ function Highlighter(options = hhDefaultOptions) {
|
|
|
1263
1267
|
const elementRect = element.getBoundingClientRect();
|
|
1264
1268
|
if (Math.round(elementRect.width) === Math.round(rect.width) && Math.round(elementRect.height) === Math.round(rect.height) && Math.round(elementRect.top) === Math.round(rect.top) && Math.round(elementRect.left) === Math.round(rect.left)) {
|
|
1265
1269
|
unmergedRects.splice(ur, 1);
|
|
1270
|
+
break;
|
|
1266
1271
|
}
|
|
1267
1272
|
}
|
|
1268
1273
|
}
|
package/package.json
CHANGED