diff --git a/src/display/editor/annotation_editor_layer.js b/src/display/editor/annotation_editor_layer.js index 9118c72b3637d..6bbe1ed9e46cd 100644 --- a/src/display/editor/annotation_editor_layer.js +++ b/src/display/editor/annotation_editor_layer.js @@ -481,6 +481,9 @@ class AnnotationEditorLayer { * @param {AnnotationEditor} editor */ add(editor) { + if (editor.parent === this && editor.isAttachedToDOM) { + return; + } this.changeParent(editor); this.#uiManager.addEditor(editor); this.attach(editor); diff --git a/test/integration/ink_editor_spec.mjs b/test/integration/ink_editor_spec.mjs index 81b1ff07999e8..6af452324af38 100644 --- a/test/integration/ink_editor_spec.mjs +++ b/test/integration/ink_editor_spec.mjs @@ -459,4 +459,45 @@ describe("Ink Editor", () => { ); }); }); + + describe("Draw several times in the same editor", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("empty.pdf", ".annotationEditorLayer"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that we can draw several times on the same canvas", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await page.click("#editorInk"); + await page.waitForSelector(".annotationEditorLayer.inkEditing"); + + const rect = await page.$eval(".annotationEditorLayer", el => { + const { x, y } = el.getBoundingClientRect(); + return { x, y }; + }); + + let xStart = rect.x + 10; + const yStart = rect.y + 10; + for (let i = 0; i < 5; i++) { + const clickHandle = await waitForPointerUp(page); + await page.mouse.move(xStart, yStart); + await page.mouse.down(); + await page.mouse.move(xStart + 50, yStart + 50); + await page.mouse.up(); + await awaitPromise(clickHandle); + xStart += 70; + } + await commit(page); + + await page.waitForSelector(getEditorSelector(0)); + }) + ); + }); + }); });