Expand description
Undoable command infrastructure for the undo/redo system.
This module provides the UndoableCmd trait for reversible operations
and common command implementations for text editing and UI interactions.
§Design Principles
- Explicit state: Commands capture all state needed for undo/redo
- Memory-efficient: Commands report their size for budget management
- Mergeable: Consecutive similar commands can merge (e.g., typing)
- Traceable: Commands include metadata for debugging and UI display
§Invariants
execute()followed byundo()restores prior state exactlyundo()followed byredo()restores the executed state exactly- Commands with
can_merge() == trueMUST successfully merge size_bytes()MUST be accurate for memory budgeting
§Failure Modes
- Stale reference: Command holds reference to deleted target
- Mitigation: Validate target existence in execute/undo
- State drift: External changes invalidate undo data
- Mitigation: Clear undo stack on external modifications
- Memory exhaustion: Unbounded history growth
- Mitigation: History stack enforces size limits via
size_bytes()
- Mitigation: History stack enforces size limits via
Structs§
- Command
Batch - A batch of commands that execute and undo together.
- Command
Metadata - Metadata attached to every command for tracing and UI display.
- Merge
Config - Configuration for command merging behavior.
- Text
Delete Cmd - Command to delete text at a position.
- Text
Insert Cmd - Command to insert text at a position.
- Text
Replace Cmd - Command to replace text at a position.
- Widget
Id - Unique identifier for a widget that commands operate on.
Enums§
- Command
Error - Errors that can occur during command execution.
- Command
Source - Source of a command - who/what triggered it.
Traits§
- Undoable
Cmd - A reversible command that can be undone and redone.
Type Aliases§
- Command
Result - Result of command execution or undo.
- Text
Apply Fn - Callback type for applying text operations.
- Text
Remove Fn - Callback type for removing text.
- Text
Replace Fn - Callback type for replacing text.