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.