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

Fix left offset when scrolling to search result #19232

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test/integration/find_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
);
});
});
});
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,4 @@
!inks_basic.pdf
!issue19182.pdf
!issue18911.pdf
!issue19207.pdf
Binary file added test/pdfs/issue19207.pdf
Binary file not shown.
9 changes: 8 additions & 1 deletion web/text_highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading