Merge pull request #17370 from calixteman/issue17368

[Editor] Make sure that all layers are disabled when an editing session is done
This commit is contained in:
calixteman 2023-12-04 16:58:41 +01:00 committed by GitHub
commit a3637e653f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 0 deletions

View File

@ -146,6 +146,11 @@ class AnnotationEditorLayer {
updateMode(mode = this.#uiManager.getMode()) {
this.#cleanup();
switch (mode) {
case AnnotationEditorType.NONE:
this.disableTextSelection();
this.togglePointerEvents(false);
this.disableClick();
break;
case AnnotationEditorType.INK:
// We always want to have an ink editor ready to draw in.
this.addInkEditorIfNeeded(false);

View File

@ -20,6 +20,7 @@ import {
kbSelectAll,
kbUndo,
loadAndWait,
scrollIntoView,
waitForStorageEntries,
} from "./test_utils.mjs";
@ -193,4 +194,66 @@ describe("Ink Editor", () => {
);
});
});
describe("Invisible layers must be disabled", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
});
afterAll(async () => {
await closePages(pages);
});
it("must check that the editor layer is disabled", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.click("#editorInk");
await page.waitForSelector(".annotationEditorLayer.inkEditing");
const rect = await page.$eval(".annotationEditorLayer", el => {
// With Chrome something is wrong when serializing a DomRect,
// hence we extract the values and just return them.
const { x, y } = el.getBoundingClientRect();
return { x, y };
});
const x = rect.x + 20;
const y = rect.y + 20;
const clickPromise = waitForPointerUp(page);
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x + 50, y + 50);
await page.mouse.up();
await clickPromise;
await commit(page);
const oneToFourteen = Array.from(new Array(13).keys(), n => n + 2);
for (const pageNumber of oneToFourteen) {
await scrollIntoView(
page,
`.page[data-page-number = "${pageNumber}"]`
);
}
await page.click("#editorInk");
await page.waitForSelector(".annotationEditorLayer:not(.inkEditing)");
const fourteenToOne = Array.from(new Array(13).keys(), n => 13 - n);
for (const pageNumber of fourteenToOne) {
await scrollIntoView(
page,
`.page[data-page-number = "${pageNumber}"]`
);
}
await page.waitForSelector(
`.page[data-page-number = "1"] .annotationEditorLayer.disabled:not(.inkEditing)`
);
})
);
});
});
});