Skip to main content

Module undo

Module undo 

Expand description

Seeing and driving undo from inside a widget.

Undo itself lives on State / UndoLog, and the host (App) drives it from Ctrl+Z. A Widget, though, only ever receives &mut AutoCommit — so on its own it can neither ask “is there anything to undo?” nor do it. That is why apps shipped a shortcut hint instead of an Undo button: not because nobody wanted one, but because a widget had no way to render one or make it work.

This module is the missing channel, and it is deliberately two one-way halves rather than a handle onto the whole State:

  • Host → widget. Once per frame the host publishes an UndoStatus to every laid-out widget via UndoControl::set_undo_status. A widget stores it (embed an UndoAccess) and reads it from draw and — the part that matters for assistive technology — from accessibility, which only gets &self.
  • Widget → host. A widget records an UndoRequest, and the host drains it via UndoControl::take_undo_request and performs it through App::perform_undo — the same method the Ctrl+Z key handler calls. There is one undo implementation, so a button and the shortcut cannot drift apart.

Both halves sweep the host’s node_map, which every laid-out widget registers itself in during build_layout. So a control works at any depth with no container forwarding — the same mechanism Widget::cursor_shape and Widget::tooltip already use.

There is a third channel in the same family, one step earlier: an app whose edits are dispatched tilo_actions actions reports the bracket around them through CommittedActions::take_committed_action, and record_dispatched_action is where a host turns that into the undo entry the two halves above then see. It sweeps node_map for the same reason they do.

Most apps need none of this directly: drop an UndoButton into a toolbar and it is wired.

Structs§

UndoAccess
The undo half of a widget, as one embeddable field: the last UndoStatus the host published, plus at most one pending UndoRequest.
UndoStatus
What the live undo history can do right now, as a widget sees it.

Enums§

LocalUndoStatus
A focused component’s observed history, or an original-field observation that is not available yet. Pending is never replaced by document history.
UndoRequest
A widget’s request that the host drive the history. The host performs it through the one undo implementation; a widget never touches the stacks.

Traits§

CommittedActions
A widget whose own controls dispatch the actions its resource exports, and so report the undo boundary around them (see record_dispatched_action).
LocalUndo
A component with its own editing history, offered the host’s keyboard undo/redo shortcut before the application document consumes it.
UndoControl
A control that shows or drives the document’s undo history (an Undo button). The host reaches every laid-out widget through its node_map, so a control works at any depth with no container forwarding.
UndoPoints
A widget that restores its ephemeral state (caret, selection) around the undo points its owner’s actions make.

Functions§

get_state
widget’s ephemeral state.
handle_local_undo_request
Offer a keyboard undo/redo to the component histories under widget.
keeps_undo_step_open
Whether widget keeps its last undo step open.
local_undo_status
Observe the same component histories the host offers its UndoRequest.
record_dispatched_action
Turn the actions a widget dispatched during the last event into exactly one undo boundary. Returns whether an entry was recorded.
set_state
Restore widget’s ephemeral state.
set_undo_status
Publish the undo status to widget if it shows it.
shortcut
Which history verb, if any, a command-modified character key means.
take_committed_action
widget’s pending action bracket, if it reports one.
take_undo_request
The undo or redo widget asked for, if any.