Browse Source

Added `loadOptions.clear` to `editor.load` method

in order to clear the internal state post load.
pull/5399/head
Artur Arseniev 3 years ago
parent
commit
bf12f90f26
  1. 8
      src/editor/index.ts
  2. 13
      src/editor/model/Editor.ts

8
src/editor/index.ts

@ -88,7 +88,7 @@ import UndoManagerModule from '../undo_manager';
import UtilsModule from '../utils'; import UtilsModule from '../utils';
import html from '../utils/html'; import html from '../utils/html';
import defaults, { EditorConfig, EditorConfigKeys } from './config/config'; import defaults, { EditorConfig, EditorConfigKeys } from './config/config';
import EditorModel from './model/Editor'; import EditorModel, { EditorLoadOptions } from './model/Editor';
import EditorView from './view/EditorView'; import EditorView from './view/EditorView';
export type ParsedRule = { export type ParsedRule = {
@ -546,12 +546,14 @@ export default class Editor implements IBaseModule<EditorConfig> {
/** /**
* Load data from the current storage. * Load data from the current storage.
* @param {Object} [options] Storage options. * @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. * @returns {Object} Loaded data.
* @example * @example
* const data = await editor.load(); * const data = await editor.load();
*/ */
async load<T extends StorageOptions>(options?: T) { async load<T extends StorageOptions>(options?: T, loadOptions: EditorLoadOptions = {}) {
return await this.em.load(options); return await this.em.load(options, loadOptions);
} }
/** /**

13
src/editor/model/Editor.ts

@ -81,6 +81,11 @@ const logs = {
error: console.error, error: console.error,
}; };
export interface EditorLoadOptions {
/** Clear the editor state (eg. dirty counter, undo manager, etc.). */
clear?: boolean;
}
export default class EditorModel extends Model { export default class EditorModel extends Model {
defaults() { defaults() {
return { return {
@ -831,11 +836,17 @@ export default class EditorModel extends Model {
* Load data from the current storage. * Load data from the current storage.
* @public * @public
*/ */
async load<T extends StorageOptions>(options?: T) { async load<T extends StorageOptions>(options?: T, loadOptions: EditorLoadOptions = {}) {
const result = await this.Storage.load(options); const result = await this.Storage.load(options);
this.loadData(result); this.loadData(result);
// Wait in order to properly update the dirty counter (#5385) // Wait in order to properly update the dirty counter (#5385)
await wait(); await wait();
if (loadOptions.clear) {
this.UndoManager.clear();
this.clearDirtyCount();
}
return result; return result;
} }

Loading…
Cancel
Save