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
setHTMLCodepushes an undo entry; callingclearHistory()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:
var editor1 = new RichTextEditor("#div_editor1");
editor1.setHTMLCode(loadedDocumentHtml);
editor1.clearHistory(); // fresh start; Undo is now disabledReset the editor when switching to a different record in a single-page app:
function openRecord(html) {
editor1.setHTMLCode(html);
editor1.clearHistory();
}Related
- editor.setHTMLCode(html)— load content (pairs naturally with clearing history).
- editor.commitBookmark()— finalize the current undo entry so the next edit starts a new one.
- All editor methods— the full JavaScript API surface.
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
var editor1 = new RichTextEditor("#div_editor1");
// The constructor is synchronous: the editor is ready on the next line.
editor1.clearHistory();React and Next.js
// 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.currenttonullin between. UseeditorRef.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.