diff --git a/src/display/editor/annotation_editor_layer.js b/src/display/editor/annotation_editor_layer.js index d2fa914ed..a0be96cb0 100644 --- a/src/display/editor/annotation_editor_layer.js +++ b/src/display/editor/annotation_editor_layer.js @@ -330,36 +330,6 @@ class AnnotationEditorLayer { } } - /** - * Add a new editor and make this addition undoable. - * @param {AnnotationEditor} editor - */ - addANewEditor(editor) { - const cmd = () => { - this.addOrRebuild(editor); - }; - const undo = () => { - editor.remove(); - }; - - this.addCommands({ cmd, undo, mustExec: true }); - } - - /** - * Add a new editor and make this addition undoable. - * @param {AnnotationEditor} editor - */ - addUndoableEditor(editor) { - const cmd = () => { - this.addOrRebuild(editor); - }; - const undo = () => { - editor.remove(); - }; - - this.addCommands({ cmd, undo, mustExec: false }); - } - /** * Get an id for an editor. * @returns {string} diff --git a/src/display/editor/editor.js b/src/display/editor/editor.js index ce601452a..224b5c56a 100644 --- a/src/display/editor/editor.js +++ b/src/display/editor/editor.js @@ -472,6 +472,7 @@ class AnnotationEditor { */ rebuild() { this.div?.addEventListener("focusin", this.#boundFocusin); + this.div?.addEventListener("focusout", this.#boundFocusout); } /** diff --git a/src/display/editor/freetext.js b/src/display/editor/freetext.js index 48c719e83..86b36845e 100644 --- a/src/display/editor/freetext.js +++ b/src/display/editor/freetext.js @@ -46,8 +46,6 @@ class FreeTextEditor extends AnnotationEditor { #editorDivId = `${this.id}-editor`; - #hasAlreadyBeenCommitted = false; - #fontSize; static _freeTextDefaultContent = ""; @@ -355,13 +353,6 @@ class FreeTextEditor extends AnnotationEditor { } super.commit(); - if (!this.#hasAlreadyBeenCommitted) { - // This editor has something and it's the first time - // it's commited so we can add it in the undo/redo stack. - this.#hasAlreadyBeenCommitted = true; - this.parent.addUndoableEditor(this); - } - this.disableEditMode(); const savedText = this.#content; const newText = (this.#content = this.#extractText().trimEnd()); @@ -371,7 +362,12 @@ class FreeTextEditor extends AnnotationEditor { const setText = text => { this.#content = text; + if (!text) { + this.remove(); + return; + } this.#setContent(); + this.rebuild(); this.#setEditorDimensions(); }; this.addCommands({ diff --git a/test/integration/freetext_editor_spec.js b/test/integration/freetext_editor_spec.js index e8979e726..1227f58db 100644 --- a/test/integration/freetext_editor_spec.js +++ b/test/integration/freetext_editor_spec.js @@ -418,6 +418,51 @@ describe("Editor", () => { }); expect(text).withContext(`In ${browserName}`).toEqual("AAAA"); + + for (let i = 0; i < 4; i++) { + await page.keyboard.down("Control"); + await page.keyboard.press("z"); + await page.keyboard.up("Control"); + await page.waitForTimeout(10); + } + + expect(await getSelectedEditors(page)) + .withContext(`In ${browserName}`) + .toEqual([]); + + await page.keyboard.down("Control"); + await page.keyboard.press("y"); + await page.keyboard.up("Control"); + await page.waitForTimeout(10); + + text = await page.$eval(`${getEditorSelector(9)} .internal`, el => { + return el.innerText; + }); + + expect(text).withContext(`In ${browserName}`).toEqual("A"); + + // Add a new A. + const editorRect = await page.$eval(getEditorSelector(9), el => { + const { x, y, width, height } = el.getBoundingClientRect(); + return { x, y, width, height }; + }); + await page.mouse.click( + editorRect.x + editorRect.width / 2, + editorRect.y + editorRect.height / 2, + { clickCount: 2 } + ); + await page.type(`${getEditorSelector(9)} .internal`, "A"); + + // Commit. + await page.mouse.click( + editorRect.x, + editorRect.y + 2 * editorRect.height + ); + + text = await page.$eval(`${getEditorSelector(9)} .internal`, el => { + return el.innerText; + }); + expect(text).withContext(`In ${browserName}`).toEqual("AA"); } }); });