Undo Manager

Undo Manager of the DocNode

DocNode provides a built-in undo manager that can be used to undo and redo transactions. It has a modular design and is completely opt-in.

The implementation is very simple (less than 80 lines), making it easy to customize or use as inspiration for your own UndoManager. For example, you could store operations in IndexedDB instead of memory, enabling persistent undo/redo when reopening documents—similar to how VS Code preserves your editing history when switching between files.

import { UndoManager } from "docnode";

const undoManager = new UndoManager(doc, { maxUndoSteps: 100 });

doc.undoManager.undo(); // undo the last transaction
doc.undoManager.redo(); // redo the last undone transaction
doc.undoManager.canUndo(); // true if there are undo steps available
doc.undoManager.canRedo(); // true if there are redo steps available

Options

Prop

Type