Skip to content

Conversation

@matt-atticus
Copy link

@matt-atticus matt-atticus commented Nov 26, 2025

Fixes an issue where highlighted search results interfere with text selection. From what we can tell, the issue stems from moving .endOfContent to the search highlight span, preventing the selection range from being extended.

Steps to reproduce the issue:

  1. Open the pdf.js demo viewer at https://mozilla.github.io/pdf.js/web/viewer.html
  2. Use the toolbar to search for a keyword e.g. "javascript"
  3. Try to create a text selection range that begins inside of, ends inside of, or spans the highlighted search result.
  4. Observe various issues:
    • flickering
    • individual characters in the search highlight cannot be smoothly selected/deselected when dragging
pdfjs-highlight-issue.mov

The fix was tested on the demo viewer locally:

npx gulp dist-install && npx gulp server

# http://localhost:8888/web/viewer.html
pdfjs-highlight-fix.mov

@matt-atticus matt-atticus marked this pull request as ready for review December 1, 2025 02:26
@nicolo-ribaudo
Copy link
Contributor

/botio preview

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_preview from @nicolo-ribaudo received. Current queue size: 0

Live output at: http://54.193.163.58:8877/a81d0fc6ccd40ac/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_preview from @nicolo-ribaudo received. Current queue size: 0

Live output at: http://54.241.84.105:8877/b10e44dc6200d7d/output.txt

@nicolo-ribaudo
Copy link
Contributor

(this PR should be labeled as chrome-specific)

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/b10e44dc6200d7d/output.txt

Total script time: 0.99 mins

Published

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/a81d0fc6ccd40ac/output.txt

Total script time: 3.51 mins

Published

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.

@nicolo-ribaudo
Copy link
Contributor

/botio integrationtest

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @nicolo-ribaudo received. Current queue size: 0

Live output at: http://54.241.84.105:8877/09db56172e1d42e/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @nicolo-ribaudo received. Current queue size: 0

Live output at: http://54.193.163.58:8877/68ec04988f22474/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/09db56172e1d42e/output.txt

Total script time: 20.46 mins

  • Integration Tests: Passed

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/68ec04988f22474/output.txt

Total script time: 40.20 mins

  • Integration Tests: Passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants