Skip to content

Commit 888df7c

Browse files
committed
[Editor] Make sure the selected editor is correctly focused after switching editing mode (bug 1990872)
1 parent 37c79c3 commit 888df7c

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

src/display/editor/editor.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,12 @@ class AnnotationEditor {
21252125
this.#altText?.toggleAltTextBadge(false);
21262126
}
21272127

2128+
focus() {
2129+
if (this.div && !this.div.contains(document.activeElement)) {
2130+
setTimeout(() => this.div?.focus({ preventScroll: true }), 0);
2131+
}
2132+
}
2133+
21282134
/**
21292135
* Unselect this editor.
21302136
*/

src/display/editor/tools.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,8 @@ class AnnotationEditorUIManager {
19481948
editor.editComment();
19491949
} else if (mustEnterInEditMode) {
19501950
editor.enterInEditMode();
1951+
} else {
1952+
editor.focus();
19511953
}
19521954
} else {
19531955
editor.unselect();

test/integration/highlight_editor_spec.mjs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
kbUndo,
3232
loadAndWait,
3333
scrollIntoView,
34+
selectEditor,
3435
selectEditors,
3536
setCaretAt,
3637
switchToEditor,
@@ -2953,4 +2954,74 @@ describe("Highlight Editor", () => {
29532954
);
29542955
});
29552956
});
2957+
2958+
describe("An ink between two highlights and focus", () => {
2959+
let pages;
2960+
2961+
beforeEach(async () => {
2962+
pages = await loadAndWait(
2963+
"tracemonkey.pdf",
2964+
".annotationEditorLayer",
2965+
null,
2966+
null,
2967+
{ highlightEditorColors: "red=#AB0000" }
2968+
);
2969+
});
2970+
2971+
afterEach(async () => {
2972+
await closePages(pages);
2973+
});
2974+
2975+
it("must check that focus move from an editor to an other", async () => {
2976+
await Promise.all(
2977+
pages.map(async ([browserName, page]) => {
2978+
await switchToHighlight(page);
2979+
2980+
let rect = await getSpanRectFromText(page, 1, "Languages");
2981+
await page.mouse.click(
2982+
rect.x + rect.width / 2,
2983+
rect.y + rect.height / 2,
2984+
{ count: 2, delay: 100 }
2985+
);
2986+
const editorSelector0 = getEditorSelector(0);
2987+
await page.waitForSelector(editorSelector0);
2988+
2989+
rect = await getSpanRectFromText(page, 1, "Abstract");
2990+
await page.mouse.click(
2991+
rect.x + rect.width / 2,
2992+
rect.y + rect.height / 2,
2993+
{ count: 2, delay: 100 }
2994+
);
2995+
const editorSelector1 = getEditorSelector(1);
2996+
await page.waitForSelector(editorSelector1);
2997+
2998+
await switchToEditor("Ink", page);
2999+
3000+
rect = await getSpanRectFromText(
3001+
page,
3002+
1,
3003+
"University of California, Irvine"
3004+
);
3005+
3006+
const clickHandle = await waitForPointerUp(page);
3007+
await page.mouse.move(rect.x, rect.y);
3008+
await page.mouse.down();
3009+
await page.mouse.move(rect.x + 50, rect.y + 50);
3010+
await page.mouse.up();
3011+
await awaitPromise(clickHandle);
3012+
3013+
await page.keyboard.press("Escape");
3014+
await page.waitForSelector(
3015+
".inkEditor.selectedEditor.draggable.disabled"
3016+
);
3017+
3018+
await selectEditor(page, editorSelector0);
3019+
for (let i = 0; i < 6; i++) {
3020+
await page.keyboard.press("Tab", { delay: 100 });
3021+
}
3022+
await waitForSelectedEditor(page, editorSelector1);
3023+
})
3024+
);
3025+
});
3026+
});
29563027
});

0 commit comments

Comments
 (0)