diff --git a/src/editor/index.ts b/src/editor/index.ts index 492499abe..184a98e2d 100644 --- a/src/editor/index.ts +++ b/src/editor/index.ts @@ -88,7 +88,7 @@ import UndoManagerModule from '../undo_manager'; import UtilsModule from '../utils'; import html from '../utils/html'; import defaults, { EditorConfig, EditorConfigKeys } from './config/config'; -import EditorModel from './model/Editor'; +import EditorModel, { EditorLoadOptions } from './model/Editor'; import EditorView from './view/EditorView'; export type ParsedRule = { @@ -546,12 +546,14 @@ export default class Editor implements IBaseModule { /** * Load data from the current storage. * @param {Object} [options] Storage options. + * @param {Object} [loadOptions={}] Load options. + * @param {Boolean} [loadOptions.clear=false] Clear the editor state (eg. dirty counter, undo manager, etc.). * @returns {Object} Loaded data. * @example * const data = await editor.load(); */ - async load(options?: T) { - return await this.em.load(options); + async load(options?: T, loadOptions: EditorLoadOptions = {}) { + return await this.em.load(options, loadOptions); } /** diff --git a/src/editor/model/Editor.ts b/src/editor/model/Editor.ts index 1de8635ca..fc56eae1d 100644 --- a/src/editor/model/Editor.ts +++ b/src/editor/model/Editor.ts @@ -81,6 +81,11 @@ const logs = { error: console.error, }; +export interface EditorLoadOptions { + /** Clear the editor state (eg. dirty counter, undo manager, etc.). */ + clear?: boolean; +} + export default class EditorModel extends Model { defaults() { return { @@ -831,11 +836,17 @@ export default class EditorModel extends Model { * Load data from the current storage. * @public */ - async load(options?: T) { + async load(options?: T, loadOptions: EditorLoadOptions = {}) { const result = await this.Storage.load(options); this.loadData(result); // Wait in order to properly update the dirty counter (#5385) await wait(); + + if (loadOptions.clear) { + this.UndoManager.clear(); + this.clearDirtyCount(); + } + return result; }