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 IUndoRedoActionRemarks
UndoRedoManager alternates the two methods: it never applies an action that is already applied, nor reverts one that is not.
Properties
| Name | Description |
|---|---|
| AllowToMergeWithPrevious | Gets a value indicating whether this action may be merged with the previous action in the undo buffer. |
| Description | Gets a human-readable description of the action, for display in an undo history. Defaults to null. |
AllowToMergeWithPrevious
Description
IUndoRedoAction.csMethods
| Name | Description |
|---|---|
| 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)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
followingActionIUndoRedoAction- The action recorded right after this one.
cancellationTokenCancellationToken- 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)