Deprecated Tiptap extension providing undo/redo functionality through keyboard shortcuts and programmatic commands
npx @tessl/cli install tessl/npm-tiptap--extension-history@3.4.0The @tiptap/extension-history package provides undo and redo functionality for Tiptap rich text editors. This deprecated extension offers a simple interface for implementing keyboard shortcuts and programmatic commands for editor history management.
npm install @tiptap/extension-historyimport { History } from '@tiptap/extension-history';
import type { HistoryOptions } from '@tiptap/extension-history';For default export:
import History from '@tiptap/extension-history';CommonJS:
const { History } = require('@tiptap/extension-history');
const History = require('@tiptap/extension-history').default;import { Editor } from '@tiptap/core';
import { History } from '@tiptap/extension-history';
// Create editor with history extension
const editor = new Editor({
extensions: [
History.configure({
depth: 100,
newGroupDelay: 500,
}),
],
});
// Use undo/redo commands
editor.commands.undo();
editor.commands.redo();
// Check if undo/redo is available
const canUndo = editor.can().undo();
const canRedo = editor.can().redo();Configure the history extension with options for depth and grouping delay.
/**
* History extension with undo/redo functionality
* @param options - Configuration options for the history extension
*/
const History: Extension<HistoryOptions>;
interface HistoryOptions {
/**
* The amount of history events that are collected before the oldest events are discarded.
* @default 100
*/
depth: number;
/**
* The delay (in milliseconds) between changes after which a new group should be started.
* @default 500
*/
newGroupDelay: number;
}Usage Example:
import { Editor } from '@tiptap/core';
import { History } from '@tiptap/extension-history';
const editor = new Editor({
extensions: [
History.configure({
depth: 50, // Keep only 50 history events
newGroupDelay: 1000, // Group changes within 1 second
}),
],
});Undo the most recent changes in the editor.
/**
* Undo recent changes
* @returns boolean - true if undo was successful, false if no changes to undo
*/
undo(): boolean;Usage Example:
// Programmatic undo
if (editor.can().undo()) {
editor.commands.undo();
}
// Check if undo is available
const canUndo = editor.can().undo();Reapply previously undone changes in the editor.
/**
* Reapply reverted changes
* @returns boolean - true if redo was successful, false if no changes to redo
*/
redo(): boolean;Usage Example:
// Programmatic redo
if (editor.can().redo()) {
editor.commands.redo();
}
// Check if redo is available
const canRedo = editor.can().redo();The extension automatically registers the following keyboard shortcuts:
interface KeyboardShortcuts {
'Mod-z': () => boolean; // Undo (Ctrl+Z on Windows/Linux, Cmd+Z on Mac)
'Shift-Mod-z': () => boolean; // Redo (Ctrl+Shift+Z)
'Mod-y': () => boolean; // Redo (Ctrl+Y on Windows/Linux, Cmd+Y on Mac)
'Mod-я': () => boolean; // Undo (Russian keyboard layout)
'Shift-Mod-я': () => boolean; // Redo (Russian keyboard layout)
}Note: The shortcuts are automatically active when the extension is installed - no additional configuration required.
/**
* Main extension class providing undo/redo functionality
*/
class Extension<HistoryOptions> {
/**
* Configure the extension with custom options
* @param options - Partial configuration options
*/
configure(options?: Partial<HistoryOptions>): Extension<HistoryOptions>;
/**
* Extension name identifier
*/
name: 'undoRedo';
}
/**
* Type alias for backward compatibility
*/
type HistoryOptions = UndoRedoOptions;
/**
* Configuration interface for the history extension
*/
interface UndoRedoOptions {
depth: number;
newGroupDelay: number;
}⚠️ Not compatible with @tiptap/extension-collaboration
This extension cannot be used together with the collaboration extension, as they have conflicting history implementations:
// ❌ Don't do this - will cause conflicts
import { Collaboration } from '@tiptap/extension-collaboration';
import { History } from '@tiptap/extension-history';
const editor = new Editor({
extensions: [
History, // ❌ Remove this when using collaboration
Collaboration.configure({
document: ydoc,
}),
],
});
// ✅ Use collaboration without history extension
const editor = new Editor({
extensions: [
// History is built into collaboration
Collaboration.configure({
document: ydoc,
}),
],
});This package is deprecated and located in the packages-deprecated directory. For new projects, consider using:
@tiptap/extensions UndoRedo directly@tiptap/extension-collaborationMigration Example:
// Old (deprecated)
import { History } from '@tiptap/extension-history';
// New (recommended)
import { UndoRedo } from '@tiptap/extensions';
const editor = new Editor({
extensions: [
UndoRedo.configure({
depth: 100,
newGroupDelay: 500,
}),
],
});Exports:
History - Main extension class (alias for UndoRedo)HistoryOptions - Configuration interface (alias for UndoRedoOptions)UndoRedo extension classCommands added to editor:
undo() - Undo recent changesredo() - Reapply reverted changesKeyboard shortcuts:
Mod-z, Shift-Mod-z, Mod-y (with Russian keyboard support)Configuration options:
depth - Number of history events to keep (default: 100)newGroupDelay - Delay for grouping changes (default: 500ms)