Skip to content

Commit a4f072f

Browse files
authored
Merge pull request #20304 from calixteman/bug1990820
[Editor] Move the focus to the comment button once editing is done (bug 1990820)
2 parents 37c79c3 + 442932f commit a4f072f

4 files changed

Lines changed: 80 additions & 1 deletion

File tree

src/display/editor/comment.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ class Comment {
7171
return this.#render(button, true);
7272
}
7373

74+
focusButton() {
75+
setTimeout(() => {
76+
(this.#commentStandaloneButton ?? this.#commentToolbarButton)?.focus();
77+
}, 0);
78+
}
79+
7480
onUpdatedColor() {
7581
if (!this.#commentStandaloneButton) {
7682
return;

src/display/editor/editor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,10 @@ class AnnotationEditor {
11621162
return this.#altText?.hasData() ?? false;
11631163
}
11641164

1165+
focusCommentButton() {
1166+
this.#comment?.focusButton();
1167+
}
1168+
11651169
addCommentButton() {
11661170
return (this.#comment ||= new Comment(this));
11671171
}

test/integration/comment_spec.mjs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
*/
1515

1616
import {
17+
awaitPromise,
1718
closePages,
19+
createPromise,
1820
dragAndDrop,
1921
getEditorSelector,
2022
getRect,
@@ -301,6 +303,71 @@ describe("Comment", () => {
301303
});
302304
});
303305

306+
describe("Focused element after editing", () => {
307+
let pages;
308+
309+
beforeEach(async () => {
310+
pages = await loadAndWait(
311+
"tracemonkey.pdf",
312+
".annotationEditorLayer",
313+
"page-width",
314+
null,
315+
{ enableComment: true }
316+
);
317+
});
318+
319+
afterEach(async () => {
320+
await closePages(pages);
321+
});
322+
323+
it("must check that the focus is moved on the comment button", async () => {
324+
await Promise.all(
325+
pages.map(async ([browserName, page]) => {
326+
await switchToHighlight(page);
327+
328+
const rect = await getSpanRectFromText(page, 1, "Languages");
329+
const x = rect.x + rect.width / 2;
330+
const y = rect.y + rect.height / 2;
331+
await page.mouse.click(x, y, { count: 2, delay: 100 });
332+
await page.waitForSelector(getEditorSelector(0));
333+
334+
const commentButtonSelector = `${getEditorSelector(0)} button.comment`;
335+
await waitAndClick(page, commentButtonSelector);
336+
337+
await page.waitForSelector("#commentManagerCancelButton", {
338+
visible: true,
339+
});
340+
const handle = await createPromise(page, resolve => {
341+
document
342+
.querySelector("button.comment")
343+
.addEventListener("focus", resolve, { once: true });
344+
});
345+
await page.click("#commentManagerCancelButton");
346+
await awaitPromise(handle);
347+
348+
await waitAndClick(page, commentButtonSelector);
349+
350+
const textInputSelector = "#commentManagerTextInput";
351+
await page.waitForSelector(textInputSelector, {
352+
visible: true,
353+
});
354+
await page.type(textInputSelector, "Hello world!");
355+
356+
await page.click("#commentManagerSaveButton");
357+
await page.waitForSelector("button.annotationCommentButton", {
358+
visible: true,
359+
});
360+
361+
await page.waitForFunction(
362+
sel => document.activeElement === document.querySelector(sel),
363+
{},
364+
"button.annotationCommentButton"
365+
);
366+
})
367+
);
368+
});
369+
});
370+
304371
describe("Comment sidebar", () => {
305372
let pages;
306373

web/comment_manager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,16 +851,18 @@ class CommentDialog {
851851
}
852852

853853
#finish() {
854+
this.#editor?.focusCommentButton();
855+
this.#editor = null;
854856
this.#textInput.value = this.#previousText = this.#commentText = "";
855857
this.#overlayManager.closeIfActive(this.#dialog);
856858
this.#textInput.style.height = "";
857859
this.#uiManager?.addEditListeners();
858860
this.#uiManager = null;
859-
this.#editor = null;
860861
}
861862

862863
destroy() {
863864
this.#uiManager = null;
865+
this.#editor = null;
864866
this.#finish();
865867
}
866868
}

0 commit comments

Comments
 (0)