Class: UndoManager
Manager class returned by undoMiddleware that allows you to perform undo/redo actions.
Constructors
Constructor
new UndoManager(
disposer,
subtreeRoot,
store?,
options
): UndoManager;
Creates an instance of UndoManager.
Do not use directly, use undoMiddleware instead.
Parameters
| Parameter | Type | Description |
|---|---|---|
disposer | ActionMiddlewareDisposer | - |
subtreeRoot | object | - |
store? | UndoStore | - |
options? | | UndoMiddlewareOptions<unknown> | undefined | - |
Returns
UndoManager
Properties
store
readonly store: UndoStore;
The store currently being used to store undo/redo action events.
Accessors
canRedo
Get Signature
get canRedo(): boolean;
If redo can be performed (if there is at least one redo action available)
Returns
boolean
canUndo
Get Signature
get canUndo(): boolean;
If undo can be performed (if there is at least one undo action available).
Returns
boolean
isUndoRecordingDisabled
Get Signature
get isUndoRecordingDisabled(): boolean;
Returns if undo recording is currently disabled or not for this particular UndoManager.
Returns
boolean
redoLevels
Get Signature
get redoLevels(): number;
The number of redo actions available.
Returns
number
redoQueue
Get Signature
get redoQueue(): readonly UndoEvent[];
The redo stack, where the first operation to redo will be the last of the array. Do not manipulate this array directly.
Returns
readonly UndoEvent[]
undoLevels
Get Signature
get undoLevels(): number;
The number of undo actions available.
Returns
number
undoQueue
Get Signature
get undoQueue(): readonly UndoEvent[];
The undo stack, where the first operation to undo will be the last of the array. Do not manipulate this array directly.
Returns
readonly UndoEvent[]
Methods
clearRedo()
clearRedo(): void;
Clears the redo queue.
Returns
void
clearUndo()
clearUndo(): void;
Clears the undo queue.
Returns
void
createGroup()
createGroup(groupName?): object;
Creates a custom group that can be continued multiple times and then ended.
Parameters
| Parameter | Type | Description |
|---|---|---|
groupName? | string | Optional group name. |
Returns
object
An API to continue/end the group.
continue()
continue<T>(fn): T;
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fn | () => T |
Returns
T
end()
end(): void;
Returns
void
dispose()
dispose(): void;
Disposes the undo middleware.
Returns
void
redo()
redo(): void;
Redoes the previous action. Will throw if there is no action to redo.
Returns
void
undo()
undo(): void;
Undoes the last action. Will throw if there is no action to undo.
Returns
void
withGroup()
Call Signature
withGroup<T>(groupName, fn): T;
Runs a synchronous code block as an undo group. Note that nested groups are allowed.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
groupName | string | Group name. |
fn | () => T | Code block. |
Returns
T
Code block return value.
Call Signature
withGroup<T>(fn): T;
Runs a synchronous code block as an undo group. Note that nested groups are allowed.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
fn | () => T | Code block. |
Returns
T
Code block return value.
withGroupFlow()
Call Signature
withGroupFlow<R>(groupName, fn): Promise<R>;
Runs an asynchronous code block as an undo group. Note that nested groups are allowed.
Type Parameters
| Type Parameter |
|---|
R |
Parameters
| Parameter | Type | Description |
|---|---|---|
groupName | string | Group name. |
fn | () => Generator<any, R, any> | Flow function. |
Returns
Promise<R>
Flow function return value.
Call Signature
withGroupFlow<R>(fn): Promise<R>;
Runs an asynchronous code block as an undo group. Note that nested groups are allowed.
Type Parameters
| Type Parameter |
|---|
R |
Parameters
| Parameter | Type | Description |
|---|---|---|
fn | () => Generator<any, R, any> | Flow function. |
Returns
Promise<R>
Flow function return value.
withoutUndo()
withoutUndo<T>(fn): T;
Skips the undo recording mechanism for the code block that gets run synchronously inside.
Type Parameters
| Type Parameter | Description |
|---|---|
T | Code block return type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
fn | () => T | Code block to run. |
Returns
T
The value returned by the code block.