Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/text_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ class TextLayerBuilder {

const parentTextLayer = anchor.parentElement?.closest(".textLayer");
const endDiv = this.#textLayers.get(parentTextLayer);
if (endDiv) {
const anchorHighlighted = anchor.classList?.contains("highlight");
if (endDiv && !anchorHighlighted) {
Copy link
Contributor

@nicolo-ribaudo nicolo-ribaudo Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fix would be more robust if we moved the highlight check to where we find the anchor:

        let anchor = modifyStart ? range.startContainer : range.endContainer;
        if (anchor.nodeType === Node.TEXT_NODE) {
          anchor = anchor.parentNode;
        }
        if (anchor.classList?.contains("highlighted")) {
          anchor = anchor.parentNode;
        }

However, I could not find a way to "break" selection with the current approach (tested with test/pdfs/chrome-text-selection-markedContent.pdf), so it's probably fine too.

endDiv.style.width = parentTextLayer.style.width;
endDiv.style.height = parentTextLayer.style.height;
anchor.parentElement.insertBefore(
Expand Down