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
UndoStatusto every laid-out widget viaUndoControl::set_undo_status. A widget stores it (embed anUndoAccess) and reads it fromdrawand — the part that matters for assistive technology — fromaccessibility, which only gets&self. - Widget → host. A widget records an
UndoRequest, and the host drains it viaUndoControl::take_undo_requestand performs it throughApp::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§
- Undo
Access - The undo half of a widget, as one embeddable field: the last
UndoStatusthe host published, plus at most one pendingUndoRequest. - Undo
Status - What the live undo history can do right now, as a widget sees it.
Enums§
- Local
Undo Status - A focused component’s observed history, or an original-field observation that is not available yet. Pending is never replaced by document history.
- Undo
Request - 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§
- Committed
Actions - A widget whose own controls dispatch the actions its resource exports,
and so report the undo boundary around them (see
record_dispatched_action). - Local
Undo - A component with its own editing history, offered the host’s keyboard undo/redo shortcut before the application document consumes it.
- Undo
Control - 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. - Undo
Points - 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
widgetkeeps 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
widgetif 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
widgetasked for, if any.