Skip to main content

UndoableCmd

Trait UndoableCmd 

Source
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§

Source

fn execute(&mut self) -> CommandResult

Execute the command, applying its effect.

Source

fn undo(&mut self) -> CommandResult

Undo the command, reverting its effect.

Source

fn description(&self) -> &str

Human-readable description for UI display.

Source

fn size_bytes(&self) -> usize

Size of this command in bytes for memory budgeting.

Source

fn metadata(&self) -> &CommandMetadata

Get the command metadata.

Source

fn as_any(&self) -> &dyn Any

Downcast to concrete type for merging.

Source

fn as_any_mut(&mut self) -> &mut dyn Any

Downcast to mutable concrete type for merging.

Provided Methods§

Source

fn redo(&mut self) -> CommandResult

Redo the command after it was undone.

Source

fn can_merge(&self, _other: &dyn UndoableCmd, _config: &MergeConfig) -> bool

Check if this command can merge with another.

Source

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).

Source

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.

Source

fn target(&self) -> Option<WidgetId>

Get the target widget ID, if any.

Source

fn debug_name(&self) -> &'static str

Debug description of the command.

Trait Implementations§

Source§

impl Debug for dyn UndoableCmd

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Implementors§