Install history with the history() extension.
import { createEditor } from "@platejs/plite";
import { history } from "@platejs/plite-history";
const editor = createEditor({
extensions: [history({ newBatchDelay: 500 })],
initialValue: [{ type: "paragraph", children: [{ text: "" }] }],
});import { createEditor } from "@platejs/plite";
import { history } from "@platejs/plite-history";
newBatchDelay defaults to 500 milliseconds. It starts a new undo batch when
an otherwise-compatible automatic native edit arrives after that idle window.
Explicit tx.history.merge() and tx.history.newBatch() decisions remain
authoritative, and no timing metadata is serialized with history.
usePliteEditor installs history by default. Disable it explicitly when a
React-owned editor should not expose history state or transaction helpers.
import { history } from "@platejs/plite-history";
import { usePliteEditor } from "@platejs/plite-react";
const editor = usePliteEditor({
extensions: [history({ enabled: false })],
initialValue,
});import { history } from "@platejs/plite-history";
import { usePliteEditor } from "@platejs/plite-react";
const editor = usePliteEditor({
Read history through state.history, write through tx.history, and use
an editor.update({ history }) policy for one controlled update.
const undoCount = editor.read((state) => state.history.undos().length);
editor.update((tx) => {
tx.history.undo();
});
editor.update({ history: "skip" }).text.insert("draft");
editor.update((tx) => {
tx.history.newBatch();
tx.text.insert("separate undo step");
});See History Editor API for the full API surface.
const undoCount = editor.read((state) => state.history.undos().length);
editor.update((tx) => {
tx.history.undo();
});
editor.update({ history: "skip" }).text.insert("draft");
editor.update((tx) => {
tx.history.newBatch();
tx.text.insert("separate undo step");
});