From b6432ef9defaa816bf51c7e9f184f7ae6b6b6033 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 10 Aug 2023 12:17:27 +0200 Subject: [PATCH] [Editor] Avoid to add a cancelled added image in the undo/redo stack We're adding the action in the undo/redo stack whatever the status of the operation was. This patch aims to add the action only when the image has been successfully added. --- src/display/editor/stamp.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/display/editor/stamp.js b/src/display/editor/stamp.js index 5a7a8952d..799093eee 100644 --- a/src/display/editor/stamp.js +++ b/src/display/editor/stamp.js @@ -38,6 +38,8 @@ class StampEditor extends AnnotationEditor { #isSvg = false; + #hasBeenAddedInUndoStack = false; + static _type = "stamp"; constructor(params) { @@ -178,7 +180,6 @@ class StampEditor extends AnnotationEditor { /** @inheritdoc */ onceAdded() { this._isDraggable = true; - this.parent.addUndoableEditor(this); this.div.focus(); } @@ -263,6 +264,10 @@ class StampEditor extends AnnotationEditor { this.#drawBitmap(width, height); this.#createObserver(); div.classList.remove("loading"); + if (!this.#hasBeenAddedInUndoStack) { + this.parent.addUndoableEditor(this); + this.#hasBeenAddedInUndoStack = true; + } } /**