RSX Code Reference
    Preparing search index...

    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.

    Index
    • Parameters

      • OptionalisInternalConstructor: boolean

      Returns UndoRedo

    • 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: number): void

      Parameters

      • value: number

      Returns void

    • 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

    • Creates a brand new scene object and begins a recordNewSceneObject 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.

      • description: string

        The name of the undo command.

      • callback: (sceneObject: SceneObject) => unknown

        The callback that performs the change.

      • OptionalisGroupable: boolean

        Determines if the command should be grouped with similar commands.

      Returns boolean

      True when the new scene object undo operation was committed and retained.

      The sceneObject must already be parented to its intended parent before calling this method.

      Example

      const newSceneObject = new SceneObject("MyNewObject");
      newSceneObject.parent = parentSceneObject;

      undoRedo.createUndoForNewSceneObject(newSceneObject, "Create MyNewObject with Renderable Component",
      (sceneObject) => sceneObject.addComponent(Renderable));

      If the callback returns false, the undo operation will be immediately reverted, if isGroupable is false.

    • 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: () => unknown

        The callback that performs the change. If the callback returns false, the undo operation will be immediately reverted when isGroupable is false.

      • 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 boolean

      True when an undo operation was committed and retained.

      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: () => unknown

        The callback that performs the change. If the callback returns false, the undo operation will be immediately reverted when isGroupable is false.

      • 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 boolean

      True when an undo operation was committed and retained.

      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 | SceneObject[]

        Scene object, or an Array of SceneObjects.

      • description: string

        The name of the undo command.

      • callback: () => void

        The callback that performs the change.

      • 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.

    • Records the complete state of multiple scene objects and invokes one callback inside a grouped undo operation. If the callback returns false, every committed object change is immediately reverted and removed from history.

      Parameters

      • sceneObjects: SceneObject[]

        Scene objects to record.

      • description: string

        Name of the grouped undo command.

      • callback: () => unknown

        Callback that performs all object changes.

      • OptionalisRecursive: boolean

        Set to true to include child objects in each recorded state.

      Returns boolean

      True when the grouped undo operation was committed and retained.

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

      Returns void

    • Loads the history that was previously stashed with stashHistory. If the history was never stashed, an empty history will be loaded. Clears the stash.

      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.

      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.

      • OptionalselectedObjects: SceneObject[]

        The selected objects that will be selected again when the command is undone or redone. If null, sceneObjects will be used for this purpose instead.

      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

    • Stashes the current undo/redo history. The history can be recreated later using loadHistoryFromStash.

      Returns void

      This overwrites any previous stashes.

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

      Returns void

    • A utility function to create a context name for an undo operation on any type of object.

      Parameters

      • targetObject: any

      Returns string

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

      Parameters

      Returns string

    onActiveUndoCommandCommited: Event<[Object, string]>

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

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

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

    onUndoRedoHistoryRewritten: Event<[]>

    Event triggered when the undo/redo stack history is rewritten, e.g. by calling clear.

    onUndoCommandAdded: Event<[p0: Immutable<HistoryEntry>, p1: boolean]>

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

    onUndoStackTopPointerChanged: Event<[p0: number]>

    Event triggered when the top of the undo stack changed.

    onRegisterCommand: Event<[p0: UndoableCommandBase]>

    Event triggered whenever a command is registered.

    onUndoCommand: Event<[p0: UndoableCommandBase]>

    Event triggered whenever a command is undone.

    onRedoCommand: Event<[p0: UndoableCommandBase]>

    Event triggered whenever a command is redone.