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 0000000000000..4c9d01ffc7745 Binary files /dev/null and b/test/pdfs/issue19207.pdf differ diff --git a/web/text_highlighter.js b/web/text_highlighter.js index ac682dba15e7a..72d883f4627af 100644 --- a/web/text_highlighter.js +++ b/web/text_highlighter.js @@ -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; }