Skip to main content

Interface: CommandHistory

Provides an undo/redo mechanism to the diagram model and components.

To make it possible to undo/redo the changes, all state modifications are organized in a form of atomic commands. These commands can be combined into a command batch to be presented to user as a single meaningful operation.

Properties

PropertyModifierTypeDescription

events

readonly

Events<CommandHistoryEvents>

Events for the command history.

redoStack

readonly

readonly Command[]

Current stack of operation which could be redone (performed again after being undone).

Latest undone commands are put at the end of the stack.

undoStack

readonly

readonly Command[]

Current stack of operation which could be undone (reverted).

Latest executed (or redone) commands are put at the end of the stack.

Methods

execute()

execute(command): void

Executes the specified command and puts its inverse into undo stack.

Parameters

ParameterType

command

Command

Returns

void

Defined in

diagram/history.ts:204


redo()

redo(): void

Redoes (performs again) the latest undone command.

If redo stack is empty, does nothing.

Returns

void

Defined in

diagram/history.ts:200


registerToUndo()

registerToUndo(command): void

Puts the inverse command directly into undo stack.

Parameters

ParameterType

command

Command

Returns

void

Defined in

diagram/history.ts:208


reset()

reset(): void

Clears undo and redo stacks of commands.

Returns

void

Defined in

diagram/history.ts:188


startBatch()

startBatch(title?): CommandBatch

Starts a new command batch which will be active either stored or discarded.

When a batch is active, all executed or registered to undo commands will be put into the batch instead of the undo stack, so it could be undo as whole later.

Starting a new batch when there is an active command batch already causes the new batch to become nested, which allows to use operations creating command batches as part of a larger operation having its own top-level batch.

Parameters

ParameterType

title?

string | TranslatedText

Returns

CommandBatch

Defined in

diagram/history.ts:219


undo()

undo(): void

Undoes (reverts) the latest executed command and puts it into redo stack.

If undo stack is empty, does nothing.

Returns

void

Defined in

diagram/history.ts:194