Skip to content

Commit 51ab037

Browse files
Improve handling of overlapping highlight colors (2)
1 parent ede3b93 commit 51ab037

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

demo.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,18 @@ <h1>Select One</h1>
187187
startParagraphId: 'p3', startParagraphOffset: 56,
188188
endParagraphId: 'p3', endParagraphOffset: 65,
189189
},
190-
{
191-
highlightId: 'hh-1735379721523',
192-
color: 'red', style: 'fill',
193-
startParagraphId: 'p1', startParagraphOffset: 237,
194-
endParagraphId: 'p1', endParagraphOffset: 250,
195-
},
196190
{
197191
highlightId: 'hh-1735379727958',
198192
color: 'yellow', style: 'fill',
199193
startParagraphId: 'p1', startParagraphOffset: 246,
200194
endParagraphId: 'p1', endParagraphOffset: 259,
201195
},
196+
{
197+
highlightId: 'hh-1735379721523',
198+
color: 'red', style: 'fill',
199+
startParagraphId: 'p1', startParagraphOffset: 237,
200+
endParagraphId: 'p1', endParagraphOffset: 250,
201+
},
202202
{
203203
highlightId: 'hh-1735479727958',
204204
color: 'yellow', style: 'fill',

highlight-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ function Highlighter(options = hhDefaultOptions) {
404404
// Set variables that depend on the range
405405
const temporaryHtmlElement = document.createElement('div');
406406
temporaryHtmlElement.appendChild(highlightRange.cloneContents());
407-
for (const hyperlink of temporaryHtmlElement.querySelectorAll('a')) hyperlink.setAttribute('onclick', 'event.preventDefault();');
407+
for (const element of temporaryHtmlElement.querySelectorAll(`a, [data-highlight-id]:not([data-highlight-id=${highlightId}])`)) element.outerHTML = element.innerHTML;
408408
rangeText = highlightRange.toString();
409409
rangeHtml = temporaryHtmlElement.innerHTML;
410410
let startParagraphIndex = annotatableParagraphIds.indexOf(startParagraphId);
@@ -859,7 +859,7 @@ function Highlighter(options = hhDefaultOptions) {
859859
} else if (activeHighlightId) {
860860
const styleTemplate = getStyleTemplate(style, 'css', null);
861861
selectionStylesheet.replaceSync(`
862-
${options.containerSelector} ::selection { --hh-color: ${colorString}; ${styleTemplate} }
862+
${options.containerSelector} ::selection { background-color: hsl(from ${colorString} h s l / 20%); --hh-color: ${colorString}; ${styleTemplate} }
863863
${options.containerSelector} rt::selection, ${options.containerSelector} img::selection { background-color: transparent; }
864864
`);
865865
} else {

0 commit comments

Comments
 (0)