Class
CommandStack
Actor managing the execution and undo/redo history of EMF commands.
@MainActor final class CommandStack
Overview
The CommandStack provides centralised command execution with full undo/redo capabilities. It maintains separate stacks for undo and redo operations, ensuring thread-safe access to command history and execution state.
Overview
The CommandStack follows a traditional undo/redo model:
-
Execution: Commands are executed and added to the undo stack
-
Undo: Commands are popped from undo stack and moved to redo stack
-
Redo: Commands are popped from redo stack and moved back to undo stack
-
Flush: Both stacks can be cleared to reset command history
Concurrency Model
The CommandStack is implemented as an actor to ensure thread-safe access to command stacks and execution state. All command operations are serialised through the actor’s message queue, preventing race conditions and ensuring consistent state transitions.
Example Usage
let commandStack = CommandStack(maxHistorySize: 100)
let result = try await commandStack.execute(setCommand)
try await commandStack.undo() // Reverses the set command
try await commandStack.redo() // Re-applies the set command
Topics
Initializers
Creates a new command stack with the specified history size.
Instance Properties
Check if redo operation is possible.
Check if undo operation is possible.
Maximum number of commands to retain in history.
Get the description of the next command that would be redone.
Get the description of the next command that would be undone.
Get the current number of commands in the redo stack.
Current execution statistics for performance monitoring.
Get the current number of commands in the undo stack.
Instance Methods
Execute a command and add it to the undo stack.
Clear all command history.
Get execution statistics for performance monitoring.
Redo the most recent undone command.
Reset execution statistics.
Undo the most recent command.
Relationships
Conforms To
See Also
Commands and Editing
Protocol defining a command that can be executed, undone, and redone.
Actor providing basic editing domain functionality for model modification coordination.