All documentation ↓← All docs

editor.clearHistory()

Empties both the undo and redo stacks. The document content is untouched — only the recorded history is cleared. Call it after you load a fresh document programmatically so the user cannot undo their way back past the content you just set.

Syntax

editor.clearHistory()

Parameters

None.

Returns

Nothing (undefined).

Behavior notes

  • Content is not affected. Clearing history removes undo/redo records only; whatever is in the editor stays exactly as it is.
  • Toolbar state refreshes. After the stacks are emptied the editor re-evaluates its selection state, so the Undo and Redo toolbar buttons correctly show as disabled.
  • Pair it with a programmatic load. Setting content with setHTMLCode pushes an undo entry; calling clearHistory() right after makes that loaded state the clean starting point.

Example usage

Load a document and make it the baseline the user cannot undo past:

Code example
var editor1 = new RichTextEditor("#div_editor1");
editor1.setHTMLCode(loadedDocumentHtml);
editor1.clearHistory();   // fresh start; Undo is now disabled

Reset the editor when switching to a different record in a single-page app:

Code example
function openRecord(html) {
    editor1.setHTMLCode(html);
    editor1.clearHistory();
}

Related

Calling editor.clearHistory() from your app

editor.clearHistory() belongs to the editor instance. Every integration below works the same way: keep the object that new RichTextEditor(...) returns, and call it on that object.

Plain JavaScript

Code example
var editor1 = new RichTextEditor("#div_editor1");
// The constructor is synchronous: the editor is ready on the next line.
editor1.clearHistory();

React and Next.js

Code example
// editorRef is filled by the RichTextEditor wrapper from the React guides.
const editorRef = useRef(null);

function onClick() {
  editorRef.current?.clearHistory();
}

return <RichTextEditor editorRef={editorRef} />;

In Vue and Angular, the wrapper components in the guides keep the instance in a component variable (editor), so the call is the same. See the React, Vue and Angular pages, or download a tested project from the guides.

If the editor is undefined

  • The call ran before the component mounted. Call it from an event handler or after the mount effect has run.
  • In React development mode, Strict Mode mounts, unmounts and mounts again, so the wrapper sets editorRef.current to null in between. Use editorRef.current?. rather than storing the instance elsewhere.
  • The editor was destroyed (editor.destroy()) when its component unmounted.

All methods: method reference · all events: event reference.