Class UndoRedo

The UndoRedo class provides undo and redo operations for changes made on objects.

Objects should be recorded before a change is made. The system will record a snapshot of the operation when the record is created and calculate the difference in a call to commitActiveOperations. If a difference is detected, the system will automatically create and insert a UndoableCommand.

To create an undo for a scene object, use createUndoForSceneObject methods. To create an undo for a regular TypeScript object, use createUndoForObject methods.

Hierarchy

  • FrameworkObject
    • UndoRedo

Constructors

  • Parameters

    • OptionalisInternalConstructor: boolean

    Returns UndoRedo

Accessors

  • get history(): Iterable<HistoryEntry>
  • Get the entire history of the Undo/Redo stack, containing both commands that can be undone and redone.

    Returns Iterable<HistoryEntry>

  • get keyWindow(): KeyWindow
  • The key window associated with this UndoRedo object.

    Returns KeyWindow

  • get topCommandId(): number
  • Returns the unique identifier for the command on top of the undo stack.

    Returns number

  • get undoStackTopPointer(): number
  • Set the undo stack pointer to a specific index in the history, undoing or redoing commands in between.

    Returns number

  • set undoStackTopPointer(value): void
  • Parameters

    • value: number

    Returns void

Methods

  • Cancels all active undo operations.

    Returns void

  • Resets the undo/redo stacks.

    Returns void

  • Clear a separators to allow grouping of commands.

    Returns void

  • Finalizes all current undo operations and generated UndoableCommand entries for active operations that contain valid changes. Generates diffs for any objects that were previously recorded using any of the Record* methods. The diff is generated by comparing the state at the time record... API was called, compared to the current object state.

    Parameters

    • OptionalselectObjectsOnUndoRedo: boolean

      Determines if the objects should be selected upon Undo/redo. For UIElements, this could refocus the element immediately, depending on the undo type. For Scene Objects and Components, this could update the selection in the KeyWindow. Defaults to true.

    Returns boolean

  • Records the current state of the object. A diff is automatically generated after the callback has been invoked. If a change is detected an UndoableCommand will be created.

    Parameters

    • object: any

      The object being changed.

    • description: string

      The name of the undo command.

    • callback: (() => void)

      The callback that performs the change.

        • (): void
        • Returns void

    • OptionalfieldPath: string

      Name to the field which should be focused when performing the undo/redo operation.

    • OptionalisGroupable: boolean

      Determines if the command should be grouped with similar commands.

    Returns void

    The object may not be a SceneObject. Changes to scene objects must be recorded through scene object specific APIs such as createUndoForSceneObject.

  • Records the complete state of the provided SceneObject including changes to Component objects assigned to the scene object. Optionally, all child objects can be recorded. A diff is automatically generated after the callback has been invoked. If a change is detected an UndoableCommand will be created.

    Parameters

    • sceneObject: SceneObject

      Scene object.

    • description: string

      The name of the undo command.

    • callback: (() => void)

      The callback that performs the change.

        • (): void
        • Returns void

    • OptionalisRecursive: boolean

      Set to true to include changes to children of the sceneObject

    • OptionalisGroupable: boolean

      Determines if the command should be grouped with similar commands.

    Returns void

    If you only modify basic SceneObject properties such as name or the transform values, it's better to use the more lightweight createUndoForSceneObjectHeaders API instead.

  • Records the current state of the provided SceneObject headers. A diff is automatically generated after the callback has been invoked. If a change is detected an UndoableCommand will be created.

    Parameters

    • sceneObjects: SceneObject[]
    • description: string

      The name of the undo command.

    • callback: (() => void)

      The callback that performs the change.

        • (): void
        • Returns void

    • OptionalisGroupable: boolean

      Determines if the command should be grouped with similar commands.

    Returns void

    The SceneObjectHeader only contains primary properties such as name, transform, active and similar basal properties. All components of the sceneObject as well as child objects are ignored. To track changes to Component or children use createUndoForSceneObject instead. Use this API for performance critical situations.

  • Inserts a separator so the next command will not be batched, even though batching criterias are fullfilled.

    Returns void

  • Removes a command from the undo/redo list, without executing it.

    Parameters

    • id: number

      Identifier of the command returned by getTopCommandIdx().

    Returns void

  • Removes all the command registered to the current undo/redo group.

    Parameters

    • name: string

      Unique name for the group.

    Returns void

  • Creates a new undo/redo group. All new commands will be registered to this group. You may remove the group and all of its commands by calling popGroup().

    For example you might require global editor-wide undo/redo operations, and also more specific ones like input in an input box. When the user is done with the input box you no longer require its undo operations and you may use groups to easily remove them.

    Parameters

    • name: string

      Unique name for the group.

    Returns void

  • Creates a brand new scene object and begins a recordSceneObject operation on the newly created scene object. Both the creation and the initially recorded set of data will be recorded as a single undo/redo command. Generally you want to call this when creating a new scene object and immediately make some initial changes to it (such as adding component or modifying their properties).

    Parameters

    • sceneObject: SceneObject

      Newly created scene object on which to initiate the record operation on.

    • OptionalisGroupable: boolean

      Determines if the command should be grouped with similar commands.

    Returns void

  • Records the current state of the object, and generates a diff with a call to commitActiveOperations. If a change is detected an UndoableCommand will be created.

    Parameters

    • object: any

      Object to record the state of.

    • fieldPath: string

      Path to the field which should be focused when performing the undo/redo operation

    • OptionalisGroupable: boolean
    • Optionaldescription: string

    Returns void

    The object may not be a SceneObject. Changes to scene objects must be recorded through scene object specific APIs such as recordSceneObject.

  • Records the complete state of the provided SceneObject including changes to Component objects assigned to the scene object. Optionally, all child objects can be recorded. A diff is generated with a call to commitActiveOperations. If a change is detected an UndoableCommand will be created.

    Parameters

    • sceneObject: SceneObject

      Scene object to record.

    • hierarchy: boolean

      Determines if the child objects will be recorded as well, otherwise just the provided object.

    • description: string

      Optional description specifying the type of changes about to be made.

    • OptionalisGroupable: boolean

      Determines if the command should be grouped with similar commands.

    Returns void

    If you only modify basic SceneObject properties such as name or the transform values, it's better to use the more lightweight recordSceneObjectHeader API instead.

  • Records the current state of the provided SceneObject header, and generates a diff with a call to commitActiveOperations. If a change is detected an UndoableCommand will be created.

    Parameters

    • sceneObject: SceneObject

      Scene object to record the state of.

    • fieldPath: string

      Name to the field which should be focused when performing the undo/redo operation.

    • Optionaldescription: string

      Description of the undo command.

    • OptionalisGroupable: boolean

      Determines if the command should be grouped with similar commands.

    Returns void

    The SceneObjectHeader only contains primary properties such as name, transform, active and similar basal properties. All components of the sceneObject as well as child objects are ignored. To track changes to Component or children use recordSceneObject instead.

  • Records the current state of the provided SceneObject headers, and generates a diff with a call to commitActiveOperations. If a change is detected an UndoableCommand will be created.

    Parameters

    • sceneObjects: SceneObject[]

      Scene objects to record the state of.

    • description: string

      Description of the undo command.

    • OptionalisGroupable: boolean

      Determines if the command should be grouped with similar commands.

    Returns void

    The SceneObjectHeader only contains primary properties such as name, transform, active and similar basal properties. All components of the sceneObject as well as child objects are ignored. To track changes to Component or children use recordSceneObject instead. Use this API for performance critical situations.

  • Executes the last command on the redo stack (last command we called undo on), re-applying its operation.

    Returns void

  • Registers a new undo command.

    Parameters

    Returns void

  • Executes the last command on the undo stack, undoing its operations.

    Returns void

  • A utitlity function to create a context name for an undo operation.

    Parameters

    Returns string

Events

onActiveUndoCommandCommited: Event<[Object, string], void>

Invoked when an active undo command was commited to an undo operation.

onUndoStackTopChanged: Event<[EnumValue<UndoStackType, number>, string], void>

Event triggered when the top of redo or undo stack changed.

onUndoRedoHistoryCleared: Event<[], void>

Event triggered when the undo/redo stack is cleared.

onUndoCommandAdded: Event<[Immutable<HistoryEntry>], void>

Event triggered when a new command is added to the undo stack.

onUndoStackTopPointerChanged: Event<[number], void>

Event triggered when the top of the undo stack changed.

onRegisterCommand: Event<[UndoableCommandBase], void>

Event triggered whenever a command is registered.

onUndoCommand: Event<[UndoableCommandBase], void>

Event triggered whenever a command is undone.

onRedoCommand: Event<[UndoableCommandBase], void>

Event triggered whenever a command is redone.