Merge pull request #19232 from nicolo-ribaudo/scroll-to-search-result
Fix left offset when scrolling to search result
This commit is contained in:
commit
7d0fe45443
@ -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
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -690,3 +690,4 @@
|
|||||||
!inks_basic.pdf
|
!inks_basic.pdf
|
||||||
!issue19182.pdf
|
!issue19182.pdf
|
||||||
!issue18911.pdf
|
!issue18911.pdf
|
||||||
|
!issue19207.pdf
|
||||||
|
|||||||
BIN
test/pdfs/issue19207.pdf
Normal file
BIN
test/pdfs/issue19207.pdf
Normal file
Binary file not shown.
@ -193,8 +193,15 @@ class TextHighlighter {
|
|||||||
span.className = `${className} appended`;
|
span.className = `${className} appended`;
|
||||||
span.append(node);
|
span.append(node);
|
||||||
div.append(span);
|
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);
|
div.append(node);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user