From 11610a9e6636e7a1c8b4110e78a1daa077d031ea Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 4 Dec 2023 23:13:31 +0100 Subject: [PATCH] [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. --- src/display/editor/ink.js | 5 +--- test/integration/ink_editor_spec.mjs | 41 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/display/editor/ink.js b/src/display/editor/ink.js index adb92fd59..08cac70ea 100644 --- a/src/display/editor/ink.js +++ b/src/display/editor/ink.js @@ -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 */, }); diff --git a/test/integration/ink_editor_spec.mjs b/test/integration/ink_editor_spec.mjs index 8a3bf48e2..7df271bae 100644 --- a/test/integration/ink_editor_spec.mjs +++ b/test/integration/ink_editor_spec.mjs @@ -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`); + }) + ); + }); + }); });