From 888df7c3193d35a31f049118c442c9b1ca535aa2 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 25 Sep 2025 22:42:32 +0200 Subject: [PATCH] [Editor] Make sure the selected editor is correctly focused after switching editing mode (bug 1990872) --- src/display/editor/editor.js | 6 ++ src/display/editor/tools.js | 2 + test/integration/highlight_editor_spec.mjs | 71 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/src/display/editor/editor.js b/src/display/editor/editor.js index 65b86094c..6dd3622d1 100644 --- a/src/display/editor/editor.js +++ b/src/display/editor/editor.js @@ -2125,6 +2125,12 @@ class AnnotationEditor { this.#altText?.toggleAltTextBadge(false); } + focus() { + if (this.div && !this.div.contains(document.activeElement)) { + setTimeout(() => this.div?.focus({ preventScroll: true }), 0); + } + } + /** * Unselect this editor. */ diff --git a/src/display/editor/tools.js b/src/display/editor/tools.js index 7ff99eee7..e12a2776f 100644 --- a/src/display/editor/tools.js +++ b/src/display/editor/tools.js @@ -1948,6 +1948,8 @@ class AnnotationEditorUIManager { editor.editComment(); } else if (mustEnterInEditMode) { editor.enterInEditMode(); + } else { + editor.focus(); } } else { editor.unselect(); diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index 2b43bc58b..730122921 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -31,6 +31,7 @@ import { kbUndo, loadAndWait, scrollIntoView, + selectEditor, selectEditors, setCaretAt, switchToEditor, @@ -2953,4 +2954,74 @@ describe("Highlight Editor", () => { ); }); }); + + describe("An ink between two highlights and focus", () => { + let pages; + + beforeEach(async () => { + pages = await loadAndWait( + "tracemonkey.pdf", + ".annotationEditorLayer", + null, + null, + { highlightEditorColors: "red=#AB0000" } + ); + }); + + afterEach(async () => { + await closePages(pages); + }); + + it("must check that focus move from an editor to an other", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await switchToHighlight(page); + + let rect = await getSpanRectFromText(page, 1, "Languages"); + await page.mouse.click( + rect.x + rect.width / 2, + rect.y + rect.height / 2, + { count: 2, delay: 100 } + ); + const editorSelector0 = getEditorSelector(0); + await page.waitForSelector(editorSelector0); + + rect = await getSpanRectFromText(page, 1, "Abstract"); + await page.mouse.click( + rect.x + rect.width / 2, + rect.y + rect.height / 2, + { count: 2, delay: 100 } + ); + const editorSelector1 = getEditorSelector(1); + await page.waitForSelector(editorSelector1); + + await switchToEditor("Ink", page); + + rect = await getSpanRectFromText( + page, + 1, + "University of California, Irvine" + ); + + const clickHandle = await waitForPointerUp(page); + await page.mouse.move(rect.x, rect.y); + await page.mouse.down(); + await page.mouse.move(rect.x + 50, rect.y + 50); + await page.mouse.up(); + await awaitPromise(clickHandle); + + await page.keyboard.press("Escape"); + await page.waitForSelector( + ".inkEditor.selectedEditor.draggable.disabled" + ); + + await selectEditor(page, editorSelector0); + for (let i = 0; i < 6; i++) { + await page.keyboard.press("Tab", { delay: 100 }); + } + await waitForSelectedEditor(page, editorSelector1); + }) + ); + }); + }); });