From 4e2aabc5cd8a6b9732241adbaf7c11c027f7a3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 16 Dec 2024 16:01:08 +0100 Subject: [PATCH] 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. --- test/integration/find_spec.mjs | 27 +++++++++++++++++++++++++++ test/pdfs/.gitignore | 1 + test/pdfs/issue19207.pdf | Bin 0 -> 5113 bytes web/text_highlighter.js | 9 ++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/issue19207.pdf diff --git a/test/integration/find_spec.mjs b/test/integration/find_spec.mjs index b73f499aee2cc..e6f05072e6f70 100644 --- a/test/integration/find_spec.mjs +++ b/test/integration/find_spec.mjs @@ -126,4 +126,31 @@ describe("find bar", () => { ); }); }); + + describe("issue19207.pdf", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("issue19207.pdf", ".textLayer", 200); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must scroll to the search result text", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + // Search for "40" + await page.click("#viewFindButton"); + await page.waitForSelector("#viewFindButton", { hidden: false }); + await page.type("#findInput", "40"); + + const highlight = await page.waitForSelector(".textLayer .highlight"); + + expect(await highlight.isIntersectingViewport()).toBeTrue(); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index fd2cc91dc036e..e619579ba44ec 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -690,3 +690,4 @@ !inks_basic.pdf !issue19182.pdf !issue18911.pdf +!issue19207.pdf diff --git a/test/pdfs/issue19207.pdf b/test/pdfs/issue19207.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4c9d01ffc77454ee011a1296070f1cdd2f58a9dd GIT binary patch literal 5113 zcm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