[Editor] Always give the focus to the ink editor when starting drawing (bug 1867588)

This way, when the editor is blurred, it can be committed and everything works fine.
It fixes issue #17373.
This commit is contained in:
Calixte Denizet 2023-12-04 23:13:31 +01:00
parent a3637e653f
commit 11610a9e66
2 changed files with 42 additions and 4 deletions

View File

@ -660,10 +660,7 @@ class InkEditor extends AnnotationEditor {
event.preventDefault();
if (
event.pointerType !== "mouse" &&
!this.div.contains(document.activeElement)
) {
if (!this.div.contains(document.activeElement)) {
this.div.focus({
preventScroll: true /* See issue #17327 */,
});

View File

@ -15,6 +15,7 @@
import {
closePages,
getEditorSelector,
getSelectedEditors,
kbRedo,
kbSelectAll,
@ -256,4 +257,44 @@ describe("Ink Editor", () => {
);
});
});
describe("Ink editor must be committed when blurred", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
});
afterAll(async () => {
await closePages(pages);
});
it("must check that the ink editor is committed", 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;
page.mouse.click(rect.x - 10, rect.y + 10);
await page.waitForSelector(`${getEditorSelector(0)}.disabled`);
})
);
});
});
});