Skip to main content

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​

ParameterTypeDescription
disposerActionMiddlewareDisposer-
subtreeRootobject-
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​

ParameterTypeDescription
groupName?stringOptional group name.

Returns​

object

An API to continue/end the group.

continue()​
continue<T>(fn): T;
Type Parameters​
Type Parameter
T
Parameters​
ParameterType
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​
ParameterTypeDescription
groupNamestringGroup name.
fn() => TCode 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​
ParameterTypeDescription
fn() => TCode 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​
ParameterTypeDescription
groupNamestringGroup 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​
ParameterTypeDescription
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 ParameterDescription
TCode block return type.

Parameters​

ParameterTypeDescription
fn() => TCode block to run.

Returns​

T

The value returned by the code block.