---
title: "tinymce.UndoManager"
description: "This class handles the undo/redo history levels for the editor. Since the built-in undo/redo has major drawbacks a custom one was needed."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.undomanager/"
md_url: "https://www.tiny.cloud/docs/tinymce/5/apis/tinymce.undomanager/index.md"
version: "5"
last_updated: "2024-03-26T08:09:19Z"
tokens: 1211
---
Important This page documents TinyMCE 5. For new projects, Tiny recommends using the latest, most up-to-date version. [See TinyMCE 8 documentation](../../../latest/apis/tinymce.undomanager/).
# tinymce.UndoManager

This class handles the undo/redo history levels for the editor. Since the built-in undo/redo has major drawbacks a custom one was needed.

## Summary

### Methods

| Name | Summary | Defined by |
| --- | --- | --- |
| [add()](#add) | Adds a new undo level/snapshot to the undo list. | `UndoManager` |
| [beforeChange()](#beforeChange) | Stores away a bookmark to be used when performing an undo action so that the selection is before the change has been made. | `UndoManager` |
| [clear()](#clear) | Removes all undo levels. | `UndoManager` |
| [extra()](#extra) | Adds an extra "hidden" undo level by first applying the first mutation and store that to the undo stack then roll back that change and do the second mutation on top of the stack. This will produce an extra undo level that the user doesn’t see until they undo. | `UndoManager` |
| [hasRedo()](#hasRedo) | Returns true/false if the undo manager has any redo levels. | `UndoManager` |
| [hasUndo()](#hasUndo) | Returns true/false if the undo manager has any undo levels. | `UndoManager` |
| [ignore()](#ignore) | Executes the specified mutator function as an undo transaction. But without adding an undo level. Any logic within the translation that adds undo levels will be ignored. So a translation can include calls to execCommand or editor.insertContent. | `UndoManager` |
| [redo()](#redo) | Redoes the last action. | `UndoManager` |
| [reset()](#reset) | Resets the undo manager levels by clearing all levels and then adding an initial level. | `UndoManager` |
| [transact()](#transact) | Executes the specified mutator function as an undo transaction. The selection before the modification will be stored to the undo stack and if the DOM changes it will add a new undo level. Any logic within the translation that adds undo levels will be ignored. So a translation can include calls to execCommand or editor.insertContent. | `UndoManager` |
| [undo()](#undo) | Undoes the last action. | `UndoManager` |

## Methods

### add()

```javascript
add(level: Object, event: DOMEvent): Object
```
Adds a new undo level/snapshot to the undo list.

#### Parameters

- `level (Object)` - Optional undo level object to add.
- `event (DOMEvent)` - Optional event responsible for the creation of the undo level.

#### Return value

- `Object` - Undo level that got added or null it a level wasn’t needed.

### beforeChange()

```javascript
beforeChange()
```
Stores away a bookmark to be used when performing an undo action so that the selection is before
the change has been made.

### clear()

```javascript
clear()
```
Removes all undo levels.

### extra()

```javascript
extra(callback1: function, callback2: function)
```
Adds an extra "hidden" undo level by first applying the first mutation and store that to the undo stack
then roll back that change and do the second mutation on top of the stack. This will produce an extra
undo level that the user doesn’t see until they undo.

#### Parameters

- `callback1 (function)` - Function that does mutation but gets stored as a "hidden" extra undo level.
- `callback2 (function)` - Function that does mutation but gets displayed to the user.

### hasRedo()

```javascript
hasRedo(): Boolean
```
Returns true/false if the undo manager has any redo levels.

#### Return value

- `Boolean` - true/false if the undo manager has any redo levels.

### hasUndo()

```javascript
hasUndo(): Boolean
```
Returns true/false if the undo manager has any undo levels.

#### Return value

- `Boolean` - true/false if the undo manager has any undo levels.

### ignore()

```javascript
ignore(callback: function)
```
Executes the specified mutator function as an undo transaction. But without adding an undo level.
Any logic within the translation that adds undo levels will be ignored. So a translation can
include calls to execCommand or editor.insertContent.

#### Parameters

- `callback (function)` - Function that gets executed and has dom manipulation logic in it.

### redo()

```javascript
redo(): Object
```
Redoes the last action.

#### Return value

- `Object` - Redo level or null if no redo was performed.

### reset()

```javascript
reset()
```
Resets the undo manager levels by clearing all levels and then adding an initial level.

### transact()

```javascript
transact(callback: function): Object
```
Executes the specified mutator function as an undo transaction. The selection
before the modification will be stored to the undo stack and if the DOM changes
it will add a new undo level. Any logic within the translation that adds undo levels will
be ignored. So a translation can include calls to execCommand or editor.insertContent.

#### Parameters

- `callback (function)` - Function that gets executed and has dom manipulation logic in it.

#### Return value

- `Object` - Undo level that got added or null it a level wasn’t needed.

### undo()

```javascript
undo(): Object
```
Undoes the last action.

#### Return value

- `Object` - Undo level or null if no undo was performed.
