Undo/Redo extension
This extension provides undo and redo support. All changes to the document will be tracked and can be removed with undo. Undone changes can be applied with redo again.
You should only integrate this extension if you don't plan to make your editor collaborative. The Collaboration extension has its own undo/redo support because people generally don't want to revert changes made by others.
Install
npm install @tiptap/extensionsUsage
import { Editor } from '@tiptap/core'
import { UndoRedo } from '@tiptap/extensions'
new Editor({
extensions: [UndoRedo],
})Settings
depth
The amount of history events that are collected before the oldest events are discarded.
Default: 100
UndoRedo.configure({
depth: 10,
})newGroupDelay
The delay between changes after which a new group should be started (in milliseconds). When changes aren’t adjacent, a new group is always started.
Default: 500
UndoRedo.configure({
newGroupDelay: 1000,
})Commands
undo()
Undo the last change.
editor.commands.undo()redo()
Redo the last change.
editor.commands.redo()Keyboard shortcuts
| Command | Windows/Linux | macOS |
|---|---|---|
| undo() | Control + Z or Control + я | Cmd + Z + or Cmd + я |
| redo() | Shift + Control + Z or Control + Y or Shift + Control + я | Shift + Cmd + Z or Cmd + Y or Shift + Cmd + я |
Source code
packages/extensions/src/undo-redo/
Minimal Install
import { Editor } from '@tiptap/core'
import { UndoRedo } from '@tiptap/extensions/undo-redo'
new Editor({
extensions: [UndoRedo],
})