Options
All
  • Public
  • Public/Protected
  • All
Menu

The UndoManager is a utility object that allows you to easily build applications with undo/redo functionality. Use the UndoManager to add actions (edits, navigation changes, graphics drawing) to the stack. The API includes a set of edit operations (add, delete, update, cut and union), created by inheriting from the Undoable class. You can inherit from the Undoable class to create custom operations that take advantage of undo/redo.

Hierarchy

  • UndoManager

Implements

Index

Constructors

constructor

  • Initializes a new instance of the UndoManager class.

    Parameters

    • app: Application

      The {@link framework.application.Application} that this instance belongs to.

    • Optional options: UndoManagerOptions

      Optional configuration settings for this instance.

    Returns UndoManager

Properties

Protected _historyStack

_historyStack: Undoable[]

Protected _status

_status: string

app

The {@link framework.application.Application} that this undo manager instance belongs to.

canRedo

canRedo: boolean

When true, there are redo operations available on the stack.

canUndo

canUndo: boolean

When true, there are undo operations available on the stack.

isRedoing

isRedoing: boolean

Whether the UndoManager is redoing.

isSuspended

isSuspended: boolean

Whether the recording of Undoable instances in the undo history has been suspended using the Suspend method.

isUndoing

isUndoing: boolean

Whether the UndoManager is undoing.

length

length: number

The number of operations stored in the history stack.

maxOperations

maxOperations: number

The maximum number of operations the UndoManager can perform. If a number less than or equal to zero is provided the number of operations is unlimited.

position

position: number

The current operation position.

rootTransaction

rootTransaction: UndoTransaction

Returns the outermost current open transaction or null if there is currently no transaction open.

Methods

Protected _checkAvailability

  • _checkAvailability(): void
  • Returns void

Protected _onTransactionAborted

  • Undo the transaction changes, then remove it from the parent.

    Parameters

    Returns void

Protected _onTransactionCommitted

  • Save changes into undo redo stack for top-level transactions.

    Parameters

    Returns void

Protected _updateStatus

  • _updateStatus(status: string): void
  • Parameters

    • status: string

    Returns void

add

  • Adds an undo operation to the stack and clears the redo stack. The redo stack’s contents last as long as undo and redo are performed successively. However, because applying a new change to an object invalidates the previous changes, as soon as a new undo operation is registered, any existing redo stack is cleared. This prevents redo from returning objects to an inappropriate prior state.

    Parameters

    • operation: Undoable

      An operation to add to the stack.

    Returns void

beginTransaction

  • Starts a transaction for recording undo operations. Undo operations recorded while a UndoTransaction is open, are added to the UndoManager only if the transaction is committed. A rollback will undo, then discard the changes which where registered while the transaction was open.

    Parameters

    • Optional name: string

      A short string describing the transaction.

    • Optional parent: UndoTransaction

      The parent transaction (for nested transactions)

    Returns UndoTransaction

clearRedo

  • clearRedo(): void
  • Clears the redo stack.

    Returns void

clearUndo

  • clearUndo(): void
  • Clears the undo stack.

    Returns void

commitTransaction

  • Commits the provided transaction. Undo operations recorded while the UndoTransaction is open, are added to the UndoManager only if the transaction is committed. Committing a transaction will commit all transactions nested below it as well. You cannot roll back a transaction once it has been committed.

    Parameters

    Returns Promise<void>

destroy

  • destroy(): void
  • Destroys this instance. Sets the history stack to null and cleans up all references.

    Returns void

getAt

  • Gets the specified operation from the stack.

    Parameters

    • index: number

      The index of the operation to return.

    Returns Undoable

getCurrentState

  • Returns an object with the following properties that describe the current state of the UndoManager: historyStack, position.

    Returns UndoManagerState

peekRedo

  • Gets the next redo operation from the stack.

    Returns Undoable

peekUndo

  • Gets the next undo operation from the stack.

    Returns Undoable

redo

  • redo(): Promise<void>
  • Moves the current position to the next redo operation and calls the operation's performRedo method.

    Returns Promise<void>

registerCommands

  • registerCommands(): void
  • Returns void

removeAt

  • removeAt(index: number): void
  • Removes the specified operation from the stack. If the index is not valid or out of bounds, then nothing happens.

    Parameters

    • index: number

      The index of the operation to remove.

    Returns void

resume

  • resume(): void
  • Resumes the recording of Undoable instances in the undo history.

    Returns void

rollbackTransaction

  • Rolls back (aborts) a transaction from a pending state. A rollback will undo, then discard the changes which where registered while the transaction was open. Rolling back a nested transaction will roll back its parent transaction as well. A transaction can only be rolled back from a pending state (after beginTransaction has been called, but before commitTransaction is called).

    Parameters

    Returns Promise<void>

setMaxOperations

  • setMaxOperations(limit: number): void
  • Sets the maximum number of operations the UndoManager can perform. If a number less than or equal to zero is provided the number of operations is unlimited.

    Parameters

    • limit: number

      The operation limit

    Returns void

suspend

  • suspend(): void
  • Suspends the recording of Undoable instances in the undo history.

    Returns void

undo

  • undo(): Promise<void>
  • Moves the current position to the next undo operation and calls the operation's performUndo method.

    Returns Promise<void>