From ae3cee95a6df3b561875bc65f6e0b5578d6faf3e Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 19 Jun 2023 21:31:26 +0200 Subject: [PATCH] [Editor] Show hidden annotations once editing is finished --- src/display/editor/annotation_editor_layer.js | 18 +++++++++ test/integration/annotation_spec.js | 37 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/display/editor/annotation_editor_layer.js b/src/display/editor/annotation_editor_layer.js index b12012b1a44d2..623465ab5c160 100644 --- a/src/display/editor/annotation_editor_layer.js +++ b/src/display/editor/annotation_editor_layer.js @@ -215,14 +215,32 @@ class AnnotationEditorLayer { disable() { this.#isDisabling = true; this.div.style.pointerEvents = "none"; + const hiddenAnnotationIds = new Set(); for (const editor of this.#editors.values()) { editor.disableEditing(); if (!editor.annotationElementId || editor.serialize() !== null) { + hiddenAnnotationIds.add(editor.annotationElementId); continue; } this.getEditableAnnotation(editor.annotationElementId)?.show(); editor.remove(); } + + if (this.#annotationLayer) { + // Show the annotations that were hidden in enable(). + const editables = this.#annotationLayer.getEditableAnnotations(); + for (const editable of editables) { + const { id } = editable.data; + if ( + hiddenAnnotationIds.has(id) || + this.#uiManager.isDeletedAnnotationElement(id) + ) { + continue; + } + editable.show(); + } + } + this.#cleanup(); if (this.isEmpty) { this.div.hidden = true; diff --git a/test/integration/annotation_spec.js b/test/integration/annotation_spec.js index 97cea0a52d929..8f386205d51cb 100644 --- a/test/integration/annotation_spec.js +++ b/test/integration/annotation_spec.js @@ -431,4 +431,41 @@ describe("ResetForm action", () => { }); }); }); + + describe("Ink widget and its popup after editing", () => { + describe("annotation-caret-ink.pdf", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait( + "annotation-caret-ink.pdf", + "[data-annotation-id='25R']" + ); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that the annotation has a popup", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await page.waitForFunction( + `document.querySelector("[data-annotation-id='25R']").hidden === false` + ); + await page.click("#editorFreeText"); + await page.waitForTimeout(10); + await page.waitForFunction( + `document.querySelector("[data-annotation-id='25R']").hidden === true` + ); + await page.click("#editorFreeText"); + await page.waitForTimeout(10); + await page.waitForFunction( + `document.querySelector("[data-annotation-id='25R']").hidden === false` + ); + }) + ); + }); + }); + }); });