Skip to main content

Module undo_support

Module undo_support 

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

  1. Execute the operation (already done when the command is created)
  2. Undo the operation (reverse the change)
  3. 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§

UndoWidgetId
Unique identifier for a widget instance.
WidgetTextEditCmd
A widget undo command for text editing.

Enums§

ListOperation
List selection operation types.
SelectionOperation
Selection state operation types.
TableOperation
Table operation types.
TextEditOperation
Text edit operation types.
TreeOperation
Tree expansion operation types.

Traits§

ListUndoExt
Extension trait for list widgets with undo support.
TableUndoExt
Extension trait for table widgets with undo support.
TextInputUndoExt
Extension trait for text input widgets with undo support.
TreeUndoExt
Extension trait for tree widgets with undo support.
UndoSupport
Trait for widgets that support undo operations.

Type Aliases§

TextEditApplyFn
Callback for applying a text edit operation.
TextEditUndoFn
Callback for undoing a text edit operation.