editor.commitBookmark()
Finalizes the editor’s current undo entry. Normally consecutive edits made close together are coalesced into a single undo step; committing marks the current step as done, so the next change begins a new, separately-undoable entry. Use it to draw a clean boundary in the undo history around a programmatic change.
Syntax
editor.commitBookmark()
Parameters
None.
Returns
Nothing (undefined).
Behavior notes
- It controls undo granularity, not content. Committing does not change the document; it only decides whether the next edit merges into the current undo step or starts a new one.
- Edits coalesce by default.Without a commit, changes that happen within a short window (the editor’s add-to-undo timeout) fold into one undo entry — committing forces the boundary immediately.
- Undo commits automatically.The editor commits the pending bookmark before performing an undo, so you rarely need this for normal typing — it is most useful around scripted edits.
Example usage
Bracket a programmatic change so it becomes its own single undo step:
var editor1 = new RichTextEditor("#div_editor1");
editor1.commitBookmark(); // close whatever came before
editor1.setHTMLCode("<b>hello world</b>");
editor1.commitBookmark(); // this insert is now its own undo stepInsert several fragments as separate undo steps instead of one merged step:
fragments.forEach(function (html) {
editor1.insertHTML(html);
editor1.commitBookmark(); // each fragment undoes independently
});Related
- editor.clearHistory()— empty the undo/redo stacks entirely.
- editor.insertHTML(html)— insert content at the caret.
- All editor methods— the full JavaScript API surface.
Calling editor.commitBookmark() from your app
editor.commitBookmark() 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.commitBookmark();React and Next.js
// editorRef is filled by the RichTextEditor wrapper from the React guides.
const editorRef = useRef(null);
function onClick() {
editorRef.current?.commitBookmark();
}
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.