Reliably discard the draft when discarding the editor
authorAlexander Ebert <ebert@woltlab.com>
Sun, 10 Sep 2023 13:17:00 +0000 (15:17 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 10 Sep 2023 13:17:00 +0000 (15:17 +0200)
See https://www.woltlab.com/community/thread/301527-zwischenspeicherung-von-nachrichten-wird-nicht-zur%C3%BCckgesetzt/

ts/WoltLabSuite/Core/Ui/Message/InlineEditor.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/InlineEditor.js

index e52f4a847be8ec38cb28fcc91da9ec0c12d51be6..143dbfa099895b7245e76e391f9717e88c6747f0 100644 (file)
@@ -589,8 +589,6 @@ class UiMessageInlineEditor implements AjaxCallbackObject {
       }
     }
 
-    getCkeditorById(this._getEditorId())!.discardDraft();
-
     this._restoreMessage();
 
     this._updateHistory(this._getHash(this._getObjectId(activeElement)));
@@ -636,7 +634,10 @@ class UiMessageInlineEditor implements AjaxCallbackObject {
    * Destroys the editor instance.
    */
   protected _destroyEditor(): void {
-    void getCkeditorById(this._getEditorId(), false)?.destroy();
+    const ckeditor = getCkeditorById(this._getEditorId(), false);
+    void ckeditor?.destroy().then(() => {
+      ckeditor.discardDraft();
+    });
   }
 
   /**
index 715ce25f272363525a3145b0aee05fa643cc0474..a70d404420fd7990379516872d6c1fb296d5bca7 100644 (file)
@@ -461,7 +461,6 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Ckeditor/Eve
                     elementData.messageBody.insertAdjacentElement("afterbegin", pollContainer);
                 }
             }
-            (0, Ckeditor_1.getCkeditorById)(this._getEditorId()).discardDraft();
             this._restoreMessage();
             this._updateHistory(this._getHash(this._getObjectId(activeElement)));
             UiNotification.show();
@@ -498,7 +497,10 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Ckeditor/Eve
          * Destroys the editor instance.
          */
         _destroyEditor() {
-            void (0, Ckeditor_1.getCkeditorById)(this._getEditorId(), false)?.destroy();
+            const ckeditor = (0, Ckeditor_1.getCkeditorById)(this._getEditorId(), false);
+            void ckeditor?.destroy().then(() => {
+                ckeditor.discardDraft();
+            });
         }
         /**
          * Returns the hash added to the url after successfully editing a message.