mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Fix left offset when scrolling to search result
When computing the left offset of the highlighted text, we cannot use .offsetLeft because the text might have been scaled through CSS, and it needs to be taken into account. Use `.getClientRects()`/`.getBoundingClientRect()` instead, which will return measurements scaled appropriately.
This commit is contained in:
parent
8985d80aef
commit
4e2aabc5cd
4 changed files with 36 additions and 1 deletions
|
@ -193,8 +193,15 @@ class TextHighlighter {
|
|||
span.className = `${className} appended`;
|
||||
span.append(node);
|
||||
div.append(span);
|
||||
return className.includes("selected") ? span.offsetLeft : 0;
|
||||
|
||||
if (className.includes("selected")) {
|
||||
const { left } = span.getClientRects()[0];
|
||||
const parentLeft = div.getBoundingClientRect().left;
|
||||
return left - parentLeft;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
div.append(node);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue