From: Alexander Ebert Date: Tue, 9 May 2023 15:49:27 +0000 (+0200) Subject: Discard the autosave draft when resetting the editor X-Git-Tag: 6.0.0_Alpha_1~125 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=fe6beb2dfb2e2309b086ddcda03a786430d90a49;p=GitHub%2FWoltLab%2FWCF.git Discard the autosave draft when resetting the editor Fixes #5462 --- diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor.ts b/ts/WoltLabSuite/Core/Component/Ckeditor.ts index ca168e4eee..9b7703e3a0 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor.ts @@ -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({ diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts index f0cd9c5f3e..1a68f60812 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Autosave.ts @@ -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)); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js index bc41b4810e..d9d96090ed 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor.js @@ -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, diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Autosave.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Autosave.js index 5521bd31df..f52d0657e8 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Autosave.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Autosave.js @@ -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; });