Expand description
Undo support for widgets. Undo support for widgets.
This module provides the UndoSupport trait that widgets can implement
to enable undo/redo functionality for their state changes.
§Design
The undo system is based on the Command Pattern. Each undoable operation creates a command that knows how to:
- Execute the operation (already done when the command is created)
- Undo the operation (reverse the change)
- Redo the operation (reapply the change)
Commands are stored in a history stack managed by HistoryManager.
§Usage
Widgets that implement UndoSupport can generate commands for their
state changes. These commands can then be pushed to a history manager
for undo/redo support.
ⓘ
use ftui_widgets::undo_support::{UndoSupport, TextEditOperation};
use ftui_runtime::undo::HistoryManager;
let mut history = HistoryManager::default();
let mut input = TextInput::new();
// Perform an edit and create an undo command
if let Some(cmd) = input.create_undo_command(TextEditOperation::Insert {
position: 0,
text: "Hello".to_string(),
}) {
history.push(cmd);
}Structs§
- Undo
Widget Id - Unique identifier for a widget instance.
- Widget
Text Edit Cmd - A widget undo command for text editing.
Enums§
- List
Operation - List selection operation types.
- Selection
Operation - Selection state operation types.
- Table
Operation - Table operation types.
- Text
Edit Operation - Text edit operation types.
- Tree
Operation - Tree expansion operation types.
Traits§
- List
Undo Ext - Extension trait for list widgets with undo support.
- Table
Undo Ext - Extension trait for table widgets with undo support.
- Text
Input Undo Ext - Extension trait for text input widgets with undo support.
- Tree
Undo Ext - Extension trait for tree widgets with undo support.
- Undo
Support - Trait for widgets that support undo operations.
Type Aliases§
- Text
Edit Apply Fn - Callback for applying a text edit operation.
- Text
Edit Undo Fn - Callback for undoing a text edit operation.