Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeFix.getClientRects(range) Not returning correct rects. #31

Open
myself3421 opened this issue Sep 13, 2022 · 5 comments
Open

RangeFix.getClientRects(range) Not returning correct rects. #31

myself3421 opened this issue Sep 13, 2022 · 5 comments

Comments

@myself3421
Copy link

myself3421 commented Sep 13, 2022

When we select text 'Vestibulum neque massa, scelerisque sit amet ligula eu, congue molestie mi. Praesent ut
varius sem. Nullam at porttitor arcu, nec lacinia nisi. Ut ac dolor vitae odio interdum
condimentum.
' from given sample pdf file then
let range = document.getSelection().getRangeAt(0);
RangeFix.getClientRects(range); returns the 3 rects in firefox and 4 rects in chrome browser.
Please find the attached document.
file-sample_150kB.pdf

@edg2s
Copy link
Owner

edg2s commented Sep 13, 2022

What are you using to render the PDF in the browser?

@myself3421
Copy link
Author

We are using pdf.js library to render PDF.

@edg2s
Copy link
Owner

edg2s commented Sep 14, 2022

If I extract the HTML from the pdf.js render, I get all 3 rects in both FF and Chrome. If I run RangeFix inside the original pdf.js online viewer, I get 6 rects in both browser (maybe 3 more for the fake selection?)

Can you provide a standalone example of the bug you describe, e.g. in a CodePen?

@myself3421
Copy link
Author

Hi,
-Please go through the link "https://codesandbox.io/s/displaying-pdf-using-react-forked-6bqup7?file=/src/components/pdf/all-pages.js"
-Open the output window in a separate tab and also open devTool console tab.
-Select the 'Vestibulum neque massa, scelerisque sit amet ligula eu, congue molestie mi. Praesent ut
varius sem. Nullam at porttitor arcu, nec lacinia nisi. Ut ac dolor vitae odio interdum
condimentum.
' text from first paragraph.
-On mouse up event, we console log the "clientRects received from RangeFix" so please check the console log.

Follow the same scenario on the Google Chrome browser, Firefox, and Edge browser.
Observe the console log on the respective browser.

Note: I have verified on windows 10
Chrome browser Version 105.0.5195.102 (Official Build) (64-bit),
Firefox 104.0.2 (64-bit), and
Microsoft Edge Version 105.0.1343.33 (Official build) (64-bit)

Observation: Received clientRects from the Below code
let range = document.getSelection().getRangeAt(0);
let rects = RangeFix.getClientRects(range);

Google Chrome: 4 clientRects
Firefox: 3 clientRects
Microsoft Edge: 4 clientRects

One more eg. select the first 4 lines from the document and check the console log on Chrome and Firefox it gives a different result.
At my end, I am receiving 10 rects in Chrome and 6 rects in Firefox.

@edg2s
Copy link
Owner

edg2s commented Sep 16, 2022

A minimal test case is:

<p>Foo <b>bar</b> baz<p>

In Chrome you get a rect for the text node "bar" as well as a rect for the <b> element. In Firefox you only get one for the <b> tag.

I don't know which behaviour is closer to spec, or if this library could detect and fix it. Generally when using the rects lists you should assume that the rects could overlap and adapt your use case accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants