From be987f2fbf0be84da4f0336c3b4ed2035f787fc6 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Tue, 7 Oct 2025 19:09:48 +0200 Subject: [PATCH] [Editor] Make sure that comment stuff is removed when an editor is deleted (bug 1992987) --- src/display/editor/editor.js | 13 ++++-- test/integration/comment_spec.mjs | 76 +++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 5 deletions(-) diff --git a/src/display/editor/editor.js b/src/display/editor/editor.js index 22a2f54d1..678d30534 100644 --- a/src/display/editor/editor.js +++ b/src/display/editor/editor.js @@ -1899,6 +1899,7 @@ class AnnotationEditor { } else { this._uiManager.removeEditor(this); } + this.hideCommentPopup(); if (this.#moveInDOMTimeout) { clearTimeout(this.#moveInDOMTimeout); @@ -1915,6 +1916,8 @@ class AnnotationEditor { this.parent = null; this.#touchManager?.destroy(); this.#touchManager = null; + this.#fakeAnnotation?.remove(); + this.#fakeAnnotation = null; } /** @@ -2166,12 +2169,12 @@ class AnnotationEditor { } this._editToolbar?.hide(); this.#altText?.toggleAltTextBadge(true); + this.hideCommentPopup(); + } + + hideCommentPopup() { if (this.hasComment) { - this._uiManager.toggleComment( - this, - /* isSelected = */ false, - /* visibility = */ false - ); + this._uiManager.toggleComment(null); } } diff --git a/test/integration/comment_spec.mjs b/test/integration/comment_spec.mjs index 503df3ce5..93195dc88 100644 --- a/test/integration/comment_spec.mjs +++ b/test/integration/comment_spec.mjs @@ -373,6 +373,36 @@ describe("Comment", () => { }) ); }); + + it("must check that the button is removed in the annotation layer", async () => { + await Promise.all( + pages.map(async ([, page]) => { + await switchToHighlight(page); + + await highlightSpan(page, 1, "Abstract"); + const editorSelector = getEditorSelector(0); + await editComment(page, editorSelector, "Hello world!"); + + await switchToHighlight(page, /* disable = */ true); + const buttonSelector = ".annotationLayer .annotationCommentButton"; + await page.waitForSelector(buttonSelector, { + visible: true, + }); + + await switchToHighlight(page); + await selectEditor(page, editorSelector); + await waitAndClick(page, `${editorSelector} button.deleteButton`); + await waitForSerialized(page, 0); + + await switchToHighlight(page, /* disable = */ true); + await page.waitForFunction( + sel => !document.querySelector(sel), + {}, + buttonSelector + ); + }) + ); + }); }); describe("Focused element after editing", () => { @@ -624,4 +654,50 @@ describe("Comment", () => { ); }); }); + + describe("Comment popup", () => { + let pages; + + beforeEach(async () => { + pages = await loadAndWait( + "tracemonkey.pdf", + ".annotationEditorLayer", + "page-width", + null, + { enableComment: true } + ); + }); + + afterEach(async () => { + await closePages(pages); + }); + + it("must check that the popup is deleted when the editor is", async () => { + await Promise.all( + pages.map(async ([, page]) => { + await switchToHighlight(page); + + await highlightSpan(page, 1, "Abstract"); + const editorSelector = getEditorSelector(0); + await editComment(page, editorSelector, "Hello world!"); + + await waitAndClick( + page, + `${editorSelector} button.annotationCommentButton` + ); + + const popupSelector = "#commentPopup"; + await page.waitForSelector(popupSelector, { visible: true }); + await waitAndClick(page, `${editorSelector} button.deleteButton`); + + // Check that the popup is removed from the DOM. + await page.waitForFunction( + sel => !document.querySelector(sel), + {}, + popupSelector + ); + }) + ); + }); + }); });