1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Merge pull request #17817 from calixteman/zoom_reset

Avoid wrong scrolling when calling zoomReset
This commit is contained in:
calixteman 2024-03-21 16:28:19 +01:00 committed by GitHub
commit 1083087eee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 2 deletions

View file

@ -55,4 +55,36 @@ describe("PDF viewer", () => {
);
});
});
describe("Zoom commands", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".textLayer .endOfContent");
});
afterAll(async () => {
await closePages(pages);
});
it("must check that zoom commands don't scroll the document", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
for (let i = 0; i < 10; i++) {
await page.evaluate(() => window.PDFViewerApplication.zoomIn());
await page.evaluate(() => window.PDFViewerApplication.zoomReset());
await page.waitForSelector(
`.page[data-page-number="1"] .textLayer .endOfContent`
);
const scrollTop = await page.evaluate(
() => document.getElementById("viewerContainer").scrollTop
);
expect(scrollTop < 100)
.withContext(`In ${browserName}`)
.toBe(true);
}
})
);
});
});
});

View file

@ -127,7 +127,6 @@ class AnnotationEditorLayerBuilder {
return;
}
this.annotationEditorLayer.destroy();
this.div.remove();
}
hide() {

View file

@ -104,7 +104,7 @@ const LAYERS_ORDER = new Map([
["textLayer", 1],
["annotationLayer", 2],
["annotationEditorLayer", 3],
["xfaLayer", 2],
["xfaLayer", 3],
]);
/**
@ -235,7 +235,12 @@ class PDFPageView {
#addLayer(div, name) {
const pos = LAYERS_ORDER.get(name);
const oldDiv = this.#layers[pos];
this.#layers[pos] = div;
if (oldDiv) {
oldDiv.replaceWith(div);
return;
}
for (let i = pos - 1; i >= 0; i--) {
const layer = this.#layers[i];
if (layer) {