1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #19144 from calixteman/no_focus_if_invisible

[Editor] Don't focus a newly added drawing if it isn't visible on screen
This commit is contained in:
calixteman 2024-12-02 14:02:01 +01:00 committed by GitHub
commit 97c7a8eb7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 66 additions and 1 deletions

View file

@ -612,4 +612,61 @@ describe("Ink Editor", () => {
);
});
});
describe("Annotation mustn't take focus if it isn't visible", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
});
afterAll(async () => {
await closePages(pages);
});
it("must check that the focus isn't taken", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToInk(page);
const rect = await getRect(page, ".annotationEditorLayer");
const x = rect.x + 20;
const y = rect.y + 20;
const clickHandle = await 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 awaitPromise(clickHandle);
await page.evaluate(() => {
window.focusedIds = [];
window.focusCallback = e => {
window.focusedIds.push(e.target.id);
};
window.addEventListener("focusin", window.focusCallback);
});
const oneToFourteen = Array.from(new Array(13).keys(), n => n + 2);
for (const pageNumber of oneToFourteen) {
await scrollIntoView(
page,
`.page[data-page-number = "${pageNumber}"]`
);
}
const ids = await page.evaluate(() => {
const { focusedIds, focusCallback } = window;
window.removeEventListener("focusin", focusCallback);
delete window.focusCallback;
delete window.focusedIds;
return focusedIds;
});
expect(ids).withContext(`In ${browserName}`).toEqual([]);
})
);
});
});
});