LuciadRIA (2026.1.02)
    Preparing search index...

    A manager of Undoables.

    You can undoables that you can undo or redo.

    You can wire a keyboard shortcut, like CTRL+Z to undo, as follows:

    // wire CTRL+Z to undo and CTRL+Y to redo. For Mac users, wire CMD+Z to undo and CMD+SHIFT+Z to redo.
    window.addEventListener("keydown", async (e) => {
    if (document.activeElement instanceof HTMLInputElement) {
    // input/text field has focus, undo/redo should affect the text and not the map
    return;
    }
    // ctrl+z or cmd+z (mac) to undo
    const isMac = window.navigator.platform.indexOf("Mac") >= 0 || window.navigator.userAgent.indexOf("Mac") >= 0;
    const isUndoKey = isMac ? (e.key === "z" && (e.metaKey && !e.shiftKey)) : (e.key === "z" && e.ctrlKey);
    if (isUndoKey) {
    e.preventDefault();
    // an undoable can update a model over the network, so undo() and redo() can be asynchronous.
    // Await them to find out whether the operation succeeded.
    try {
    await SAMPLE_UNDO_MANAGER.undo();
    } catch (error) {
    console.error("Could not undo", error);
    }
    }
    // ctrl+y or cmd+shift+z (mac) to redo
    const isRedoKey = isMac ? (e.key === "z" && e.metaKey && e.shiftKey) : (e.key === "y" && e.ctrlKey);
    if (isRedoKey) {
    e.preventDefault();
    try {
    await SAMPLE_UNDO_MANAGER.redo();
    } catch (error) {
    console.error("Could not redo", error);
    }
    }
    });

    You usually create undoables in response to an event from the API, and then add them to an UndoManager. You can find a list of common events in Undoable.

    This example shows how to create Undoables in LuciadRIA:

    /**
    * Adds sample undo/redo support to an EditController.
    * @param editController The EditController to add sample undo/redo support to
    * @param undoManager The UndoManager to add the undoable to
    */
    export const addEditUndoSupport = (editController: EditController, undoManager: UndoManager = SAMPLE_UNDO_MANAGER): Handle => {
    let lastShape = editController.feature.shape ? editController.feature.shape.copy() : null;
    let propertyValueBeforeEditing: unknown[] | null = null;
    const editHandle = editController.on("EditShape", ({shape, status}) => {
    if (status === EditShapeStatus.FINISHED) {
    const label = `edit ${shapeToString(shape)}`;
    const newShape = shape ? shape.copy() : null;
    addChangeShapeUndoable(editController.map!, editController.layer, editController.feature, lastShape, newShape, label, undoManager);
    lastShape = newShape ? newShape.copy() : null;
    }
    });
    const propertyHandle = editController.on("EditProperty", ({changes, status}) => {
    if (status === EditPropertyStatus.FINISHED) {
    const label = `edit property`;
    const changesWithOldValues = changes.map((change, idx) => {
    return {
    ...change,
    oldValue: propertyValueBeforeEditing![idx],
    }
    });
    addChangePropertyUndoable(editController.map!, editController.layer, editController.feature, changesWithOldValues,
    label, undoManager);
    propertyValueBeforeEditing = null;
    } else {
    // capture the previous value of the first in-progress event only, as this will have the correct value from before the editing operation
    if (propertyValueBeforeEditing == null) {
    propertyValueBeforeEditing = changes.map(change => change.oldValue);
    }
    }
    });
    const restartHandle = editController.on("Restarted", () => {
    if (!ChangeShapeUndoable.isRestartFromUndoable) {
    // restart from outside undo/redo, track the change
    const shape = editController.feature.shape;
    const label = `restart ${shapeToString(shape)}`;
    const newShape = shape ? shape.copy() : null;
    addChangeShapeUndoable(editController.map!, editController.layer, editController.feature, lastShape, newShape, label, undoManager);
    lastShape = newShape ? newShape.copy() : null;
    propertyValueBeforeEditing = null;
    }
    lastShape = editController.feature.shape ? editController.feature.shape.copy() : null;
    });
    const deactivateHandle = editController.on("Deactivated", () => {
    restartHandle.remove();
    editHandle.remove();
    deactivateHandle.remove();
    });
    return {
    remove: () => {
    restartHandle.remove();
    editHandle.remove();
    propertyHandle.remove();
    deactivateHandle.remove();
    }
    }
    }

    You can find the full source, and more examples, in toolbox/ria/core/util/SampleUndoSupport.ts.

    See the Adding undo/redo support to your application guide for more information on how to work with undo/redo in LuciadRIA.

    2022.1

    • Creates a new UndoManager instance

      Parameters

      • Optionallimit: number

        The maximum amount of Undoable this manager should track on its undoStack. Defaults to 10.

      Returns UndoManager

    • get limit(): number

      Returns the current limit of the UndoManager

      Returns number

    • set limit(limit: number): void

      Sets the limit of the UndoManager.

      This limits the size of the undoStack. If the size of the undoStack exceeds the limit, the oldest Undoables on the stack are removed.

      If the new limit is lower than the old limit, the oldest items on the undoStack will be discarded, without applying them.

      Parameters

      • limit: number

        The new limit. Must be strictly positive.

      Returns void

    • get redoStack(): Undoable[]

      Returns a copy of the redo stack. The upcoming undoable is the last element in the array.

      You can use this stack to show one or more upcoming undoables, for example in a drop-down box of a redo button.

      Returns Undoable[]

    • get undoStack(): Undoable[]

      Returns a copy of the undo stack. The upcoming undoable is the last element in the array.

      You can use this stack to show one or more upcoming undoables, for example in a drop-down box of an undo button.

      Returns Undoable[]

    • Indicates if this UndoManager can redo.

      An UndoManager can redo when there is at least 1 Undoable on the redoStack.

      Returns boolean

    • Indicates if this UndoManager can undo.

      An UndoManager can undo when there is at least 1 Undoable on the undoStack.

      Returns boolean

    • Redoes the last Undoable on the redoStack. This Undoable then moves to the undoStack, immediately, before it is applied.

      Undoable.redo can be asynchronous. If it is, this method returns a promise that resolves once that Undoable is redone, and this UndoManager waits for it before it applies the next Undoable. Calls to undo and redo that arrive in the meantime are queued, and applied in the order in which you called them.

      If every Undoable in this UndoManager is synchronous, the returned promise never rejects, and you can ignore it. As soon as one of them can be asynchronous, await it inside a try/catch block, so that you find out whether the Undoable was applied and can report a failed model update to your user.

      If Undoable.redo fails, the Undoable still moves to the undoStack, and the operations queued behind it are still applied. A synchronous Undoable on an idle UndoManager throws its error synchronously, as it did before 2026.1, so existing error handling around this method keeps working. An asynchronous Undoable, or a synchronous one that is queued behind an asynchronous operation, rejects the returned promise instead.

      Returns Promise<void>

      a promise that resolves once the Undoable is redone, or rejects if redoing it asynchronously failed. Note that this method returned void before 2026.1.

    • Resets the UndoManager. This empties the Undoables;

      This does not cancel Undoables that are being undone or redone, or that are queued behind them. They are still applied, and can still change your models after this call. Await the promises that undo and redo return if you need all of them to be applied before you reset.

      Returns void

    • Undoes the last Undoable on the undoStack. This Undoable then moves to the redoStack, immediately, before it is applied.

      Undoable.undo can be asynchronous. If it is, this method returns a promise that resolves once that Undoable is undone, and this UndoManager waits for it before it applies the next Undoable. Calls to undo and redo that arrive in the meantime are queued, and applied in the order in which you called them.

      If every Undoable in this UndoManager is synchronous, the returned promise never rejects, and you can ignore it. As soon as one of them can be asynchronous, await it inside a try/catch block, so that you find out whether the Undoable was applied and can report a failed model update to your user.

      If Undoable.undo fails, the Undoable still moves to the redoStack, and the operations queued behind it are still applied. A synchronous Undoable on an idle UndoManager throws its error synchronously, as it did before 2026.1, so existing error handling around this method keeps working. An asynchronous Undoable, or a synchronous one that is queued behind an asynchronous operation, rejects the returned promise instead.

      Returns Promise<void>

      a promise that resolves once the Undoable is undone, or rejects if undoing it asynchronously failed. Note that this method returned void before 2026.1.

    • An event that fires whenever an undo was performed. The performed Undoable is passed as argument to the callback.

      Parameters

      • event: "Undo"
      • callback: (undoable: Undoable) => void

      Returns Handle

      2026.0

    • An event that fires whenever an redo was performed. The performed Undoable is passed as argument to the callback.

      Parameters

      • event: "Redo"
      • callback: (undoable: Undoable) => void

      Returns Handle

      2026.0

    • An event that fires whenever the undoStack of this UndoManager changes. UndoStackChanged

      Parameters

      • event: "UndoStackChanged"
      • callback: () => void

      Returns Handle

    • An event that fires whenever the redoStack of this UndoManager changes. RedoStackChanged

      Parameters

      • event: "RedoStackChanged"
      • callback: () => void

      Returns Handle

    • An event that fires whenever the limit of this UndoManager changes. LimitChanged

      Parameters

      • event: "LimitChanged"
      • callback: () => void

      Returns Handle