All documentation ↓← All docs

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:

Code example
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 step

Insert several fragments as separate undo steps instead of one merged step:

Code example
fragments.forEach(function (html) {
    editor1.insertHTML(html);
    editor1.commitBookmark();   // each fragment undoes independently
});

Related

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

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

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?.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.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.