etui/undo

Types

Generic undo/redo history.

  • present, the current value.
  • past, previous values, most-recent first.
  • future, values undone and available to redo, most-recent first.
  • max_size, maximum entries kept in past (0 = unlimited).
pub type UndoStack(a) {
  UndoStack(
    past: List(a),
    present: a,
    future: List(a),
    max_size: Int,
  )
}

Constructors

  • UndoStack(
      past: List(a),
      present: a,
      future: List(a),
      max_size: Int,
    )

Values

pub fn can_redo(stack: UndoStack(a)) -> Bool

True if there is at least one future state to redo to.

pub fn can_undo(stack: UndoStack(a)) -> Bool

True if there is at least one past state to undo to.

pub fn current(stack: UndoStack(a)) -> a

The current value.

pub fn push(stack: UndoStack(a), new_value: a) -> UndoStack(a)

Record new_value as the new present, moving the old present into past. Clears the future (redo history) since the branch diverged.

pub fn redo(stack: UndoStack(a)) -> UndoStack(a)

Redo: move present to past, restore the most-recent future as present. No-op if there is nothing to redo.

pub fn reset(stack: UndoStack(a), initial: a) -> UndoStack(a)

Reset to initial state, clearing all history.

pub fn undo(stack: UndoStack(a)) -> UndoStack(a)

Undo: move present to future, restore the most-recent past as present. No-op if there is nothing to undo.

pub fn undo_depth(stack: UndoStack(a)) -> Int

Number of past entries available to undo.

pub fn undo_new(
  initial: a,
  max_size max_size: Int,
) -> UndoStack(a)

Create a new stack with an initial present value. max_size limits how many past entries are retained (0 = unlimited).

Search Document