pub trait UndoableCmd: Send + Sync {
Show 13 methods
// Required methods
fn execute(&mut self) -> CommandResult;
fn undo(&mut self) -> CommandResult;
fn description(&self) -> &str;
fn size_bytes(&self) -> usize;
fn metadata(&self) -> &CommandMetadata;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
// Provided methods
fn redo(&mut self) -> CommandResult { ... }
fn can_merge(&self, _other: &dyn UndoableCmd, _config: &MergeConfig) -> bool { ... }
fn merge_text(&self) -> Option<&str> { ... }
fn accept_merge(&mut self, _other: &dyn UndoableCmd) -> bool { ... }
fn target(&self) -> Option<WidgetId> { ... }
fn debug_name(&self) -> &'static str { ... }
}Expand description
A reversible command that can be undone and redone.
Commands capture all state needed to execute, undo, and redo an operation. They support merging for batching related operations (like consecutive typing).
Required Methods§
Sourcefn execute(&mut self) -> CommandResult
fn execute(&mut self) -> CommandResult
Execute the command, applying its effect.
Sourcefn undo(&mut self) -> CommandResult
fn undo(&mut self) -> CommandResult
Undo the command, reverting its effect.
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Human-readable description for UI display.
Sourcefn size_bytes(&self) -> usize
fn size_bytes(&self) -> usize
Size of this command in bytes for memory budgeting.
Sourcefn metadata(&self) -> &CommandMetadata
fn metadata(&self) -> &CommandMetadata
Get the command metadata.
Sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Downcast to mutable concrete type for merging.
Provided Methods§
Sourcefn redo(&mut self) -> CommandResult
fn redo(&mut self) -> CommandResult
Redo the command after it was undone.
Sourcefn can_merge(&self, _other: &dyn UndoableCmd, _config: &MergeConfig) -> bool
fn can_merge(&self, _other: &dyn UndoableCmd, _config: &MergeConfig) -> bool
Check if this command can merge with another.
Sourcefn merge_text(&self) -> Option<&str>
fn merge_text(&self) -> Option<&str>
Merge another command into this one.
Returns the text to append if merging is possible. The default implementation returns None (no merge).
Sourcefn accept_merge(&mut self, _other: &dyn UndoableCmd) -> bool
fn accept_merge(&mut self, _other: &dyn UndoableCmd) -> bool
Accept a merge from another command.
The full command reference is passed to allow implementations to extract position or other context needed for correct merge behavior.
Sourcefn debug_name(&self) -> &'static str
fn debug_name(&self) -> &'static str
Debug description of the command.