Merge pull request #20780 from wooorm/wooorm/dismiss-popups

Add support for dismissing comment popups with click outside
This commit is contained in:
calixteman 2026-03-04 15:24:29 +01:00 committed by GitHub
commit ce5f34ba13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 92 additions and 0 deletions

View File

@ -901,6 +901,7 @@ class AnnotationEditorLayer {
const currentMode = this.#uiManager.getMode(); const currentMode = this.#uiManager.getMode();
if ( if (
currentMode === AnnotationEditorType.STAMP || currentMode === AnnotationEditorType.STAMP ||
currentMode === AnnotationEditorType.POPUP ||
currentMode === AnnotationEditorType.SIGNATURE currentMode === AnnotationEditorType.SIGNATURE
) { ) {
this.#uiManager.unselectAll(); this.#uiManager.unselectAll();

View File

@ -2393,6 +2393,7 @@ class AnnotationEditorUIManager {
ed.unselect(); ed.unselect();
} }
} }
this.#commentManager?.destroyPopup();
this.#selectedEditors.clear(); this.#selectedEditors.clear();
this.#selectedEditors.add(editor); this.#selectedEditors.add(editor);
@ -2583,6 +2584,8 @@ class AnnotationEditorUIManager {
return; return;
} }
this.#commentManager?.destroyPopup();
if (!this.hasSelection) { if (!this.hasSelection) {
return; return;
} }

View File

@ -21,6 +21,7 @@ import {
dragAndDrop, dragAndDrop,
getEditorSelector, getEditorSelector,
getRect, getRect,
getSpanRectFromText,
highlightSpan, highlightSpan,
kbModifierDown, kbModifierDown,
kbModifierUp, kbModifierUp,
@ -1176,4 +1177,91 @@ describe("Comment", () => {
); );
}); });
}); });
describe("Must close comment popups (bug 1989406)", () => {
let pages;
beforeEach(async () => {
pages = await loadAndWait(
"tracemonkey.pdf",
".annotationEditorLayer",
"page-fit",
null,
{ enableComment: true }
);
});
afterEach(async () => {
await closePages(pages);
});
it("must close a comment popup on escape", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToHighlight(page);
await highlightSpan(page, 1, "Abstract");
await editComment(page, getEditorSelector(0), "hi");
const rect = await getSpanRectFromText(page, 1, "Introduction");
// Unfocus.
await page.mouse.click(rect.x, rect.y);
await waitAndClick(page, ".annotationCommentButton");
await page.waitForSelector("#commentPopup", { visible: true });
await page.keyboard.press("Escape");
await page.waitForSelector("#commentPopup", { hidden: true });
})
);
});
it("must close a comment popup on click outside", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToHighlight(page);
await highlightSpan(page, 1, "Abstract");
await editComment(page, getEditorSelector(0), "hi");
const rect = await getSpanRectFromText(page, 1, "Introduction");
// Unfocus.
await page.mouse.click(rect.x, rect.y);
await waitAndClick(page, ".annotationCommentButton");
await page.waitForSelector("#commentPopup", { visible: true });
// Click outside the popup.
await page.mouse.click(rect.x, rect.y);
await page.waitForSelector("#commentPopup", { hidden: true });
})
);
});
it("must close a comment popup on click on other highlight", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToHighlight(page);
await highlightSpan(page, 1, "Abstract");
await editComment(page, getEditorSelector(0), "hello");
await highlightSpan(page, 1, "Introduction");
await editComment(page, getEditorSelector(1), "world");
// Open "Abstract" comment popup.
await waitAndClick(page, ".annotationCommentButton");
await page.waitForSelector("#commentPopup", { visible: true });
// Click on "Introduction" highlight.
await waitAndClick(page, getEditorSelector(1));
await page.waitForSelector("#commentPopup", { hidden: true });
})
);
});
});
}); });