IUndoRedoAction Interface

Represents a single undoable/redoable action. Implementations encapsulate both how to apply a change (IUndoRedoAction.ExecuteAsync) and how to revert it (IUndoRedoAction.UnExecuteAsync).

public interface IUndoRedoAction

Remarks

UndoRedoManager alternates the two methods: it never applies an action that is already applied, nor reverts one that is not.

Properties

NameDescription
AllowToMergeWithPreviousGets a value indicating whether this action may be merged with the previous action in the undo buffer.
DescriptionGets a human-readable description of the action, for display in an undo history. Defaults to null.

AllowToMergeWithPrevious

Gets a value indicating whether this action may be merged with the previous action in the undo buffer.

bool AllowToMergeWithPrevious { get; }

Property value

bool

Gets a human-readable description of the action, for display in an undo history. Defaults to null.

public string? Description { get; }

Property value

string?

Methods

NameDescription
ExecuteAsync(CancellationToken)Applies the change encapsulated by this action.
TryToMergeAsync(IUndoRedoAction, CancellationToken)Attempts to merge a following action into this one instead of recording it as a separate step. Useful for long chains of consecutive operations of the same kind (e.g. dragging or typing).
UnExecuteAsync(CancellationToken)Reverts the change previously applied by IUndoRedoAction.ExecuteAsync.

ExecuteAsync(CancellationToken)

Applies the change encapsulated by this action.

ValueTask ExecuteAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask

TryToMergeAsync(IUndoRedoAction, CancellationToken)

Attempts to merge a following action into this one instead of recording it as a separate step. Useful for long chains of consecutive operations of the same kind (e.g. dragging or typing).

ValueTask<bool> TryToMergeAsync(IUndoRedoAction followingAction, CancellationToken cancellationToken = default)

Parameters

followingAction IUndoRedoAction
The action recorded right after this one.
cancellationToken CancellationToken
A token to cancel the operation.

Returns

ValueTask<bool> true if followingAction was merged into this action; otherwise false.

Remarks

followingAction is in the same applied state as this action: both are already applied at the top level and inside an TransactionExecutionMode.Immediate transaction, and neither is applied inside a TransactionExecutionMode.Deferred one. An implementation must therefore absorb followingAction's effect without applying it.

Returning true discards followingAction: it is never executed nor reverted by the manager again, so this action becomes responsible for applying and reverting both effects from its own IUndoRedoAction.ExecuteAsync and IUndoRedoAction.UnExecuteAsync.

UnExecuteAsync(CancellationToken)

Reverts the change previously applied by IUndoRedoAction.ExecuteAsync.

ValueTask UnExecuteAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask