Discard the autosave draft when resetting the editor
authorAlexander Ebert <ebert@woltlab.com>
Tue, 9 May 2023 15:49:27 +0000 (17:49 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 9 May 2023 15:49:27 +0000 (17:49 +0200)
Fixes #5462

ts/WoltLabSuite/Core/Component/Ckeditor.ts
ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Autosave.js

index ca168e4eee69e9875d700f53d50c1746192d73ac..9b7703e3a0b2fd03ad748ed2560e67fc92c9935c 100644 (file)
@@ -160,7 +160,7 @@ function initializeConfiguration(element: HTMLElement, features: Features, bbcod
   (configuration as any).woltlabBbcode = bbcodes;
 
   if (features.autosave !== "") {
-    initializeAutosave(features.autosave, configuration);
+    initializeAutosave(element, configuration, features.autosave);
   }
 
   dispatchToCkeditor(element).setupConfiguration({
index f0cd9c5f3ee3e7ced1a6678348955404e5287c83..1a68f608126b1b688b3fd166fd1473aca6a7a90a 100644 (file)
@@ -13,7 +13,7 @@ import { getPhrase } from "../../Language";
 import { escapeHTML } from "../../StringUtil";
 
 import type { ClassicEditor, EditorConfig } from "./Types";
-import { dispatchToCkeditor } from "./Event";
+import { dispatchToCkeditor, listenToCkeditor } from "./Event";
 
 type Payload = {
   html: string;
@@ -176,15 +176,17 @@ function removeExpiredDrafts(): void {
     });
 }
 
-export function initializeAutosave(autosave: string, configuration: EditorConfig): void {
+export function initializeAutosave(element: HTMLElement, configuration: EditorConfig, identifier: string): void {
   removeExpiredDrafts();
 
   configuration.autosave = {
     save(editor) {
-      saveDraft(autosave, editor.data.get());
+      saveDraft(identifier, editor.data.get());
 
       return Promise.resolve();
     },
     waitingTime: 15_000,
   };
+
+  listenToCkeditor(element).reset(() => deleteDraft(identifier));
 }
index bc41b4810e24c22c916c1e5bdb1318aecd815270..d9d96090ed6adee99638d525e07f94c7457cb6b4 100644 (file)
@@ -113,7 +113,7 @@ define(["require", "exports", "tslib", "./Ckeditor/Attachment", "./Ckeditor/Medi
         const configuration = (0, Configuration_1.createConfigurationFor)(features);
         configuration.woltlabBbcode = bbcodes;
         if (features.autosave !== "") {
-            (0, Autosave_1.initializeAutosave)(features.autosave, configuration);
+            (0, Autosave_1.initializeAutosave)(element, configuration, features.autosave);
         }
         (0, Event_1.dispatchToCkeditor)(element).setupConfiguration({
             configuration,
index 5521bd31df28050f8f3db15eb59298f4a1c81de1..f52d0657e817f8c4bec861efcd0e6e7677323faf 100644 (file)
@@ -143,15 +143,16 @@ define(["require", "exports", "../../Core", "../../Language", "../../StringUtil"
             }
         });
     }
-    function initializeAutosave(autosave, configuration) {
+    function initializeAutosave(element, configuration, identifier) {
         removeExpiredDrafts();
         configuration.autosave = {
             save(editor) {
-                saveDraft(autosave, editor.data.get());
+                saveDraft(identifier, editor.data.get());
                 return Promise.resolve();
             },
             waitingTime: 15000,
         };
+        (0, Event_1.listenToCkeditor)(element).reset(() => deleteDraft(identifier));
     }
     exports.initializeAutosave = initializeAutosave;
 });