pub struct UndoStack { /* private fields */ }Expand description
One undo history over the stores it UndoStack::watches: units are turns (everything one
event’s dispatch changed), inverted, not snapshots. Enabling it turns on standing value
capture; drop the stack and the capture stops.
Implementations§
Source§impl UndoStack
impl UndoStack
Sourcepub fn new(levels: usize) -> UndoStack
pub fn new(levels: usize) -> UndoStack
A stack holding at most levels units: the bound on what history keeps in RAM.
Sourcepub fn watch<T: ApplyField + Identified + Clone + 'static>(
&self,
store: Store<Keyed<T>>,
)
pub fn watch<T: ApplyField + Identified + Clone + 'static>( &self, store: Store<Keyed<T>>, )
Bring one store under this history. Only watched stores are captured; a change in any other store passes the stack by.
Sourcepub fn grouped(&self, label: &'static str, f: impl FnOnce())
pub fn grouped(&self, label: &'static str, f: impl FnOnce())
Everything f changes lands as one unit named label: a multi-field commit, an
inspector applying twelve properties.
Sourcepub fn begin_group(&self, label: &'static str) -> UndoGroup
pub fn begin_group(&self, label: &'static str) -> UndoGroup
Keep one undo unit open across event turns, until the returned guard is dropped. Nested groups join the outer unit and retain its label. Keep the guard only for the duration of the interaction: all watched edits in that interval belong to the group.
Sourcepub fn checkpoint(&self) -> UndoCheckpoint
pub fn checkpoint(&self) -> UndoCheckpoint
Preserve history before an atomic persistence operation. Failed commits must restore both the database/cache and this checkpoint, including an existing redo branch.
pub fn restore_checkpoint(&self, checkpoint: UndoCheckpoint)
pub fn can_undo(&self) -> Signal<bool>
pub fn can_redo(&self) -> Signal<bool>
Sourcepub fn undo_label(&self) -> Signal<String>
pub fn undo_label(&self) -> Signal<String>
The next undo unit’s display label (“Name”, or whatever the resolver makes of it), empty when there is nothing to undo. What a menu title interpolates.
pub fn redo_label(&self) -> Signal<String>
Sourcepub fn set_label_resolver(&self, f: impl Fn(&'static str) -> String + 'static)
pub fn set_label_resolver(&self, f: impl Fn(&'static str) -> String + 'static)
How unit labels become display text (Fluent lookup, capitalization); the default capitalizes the raw label.
Sourcepub fn set_transient_context(
&self,
capture: impl Fn() -> Rc<dyn Any> + 'static,
restore: impl Fn(&dyn Any) + 'static,
)
pub fn set_transient_context( &self, capture: impl Fn() -> Rc<dyn Any> + 'static, restore: impl Fn(&dyn Any) + 'static, )
Ride transient UI state (a selection, a scroll position) along the history: captured, never persisted (docs/model.md “Transient UI state”).
capture runs as each unit seals, so a snapshot is the UI state at that point of
document history, including any selection writes the same turn made. Undo restores the
snapshot of the unit history lands on: the previous unit’s, or the base snapshot
(taken here, at install) once the last unit is undone; redo restores the redone unit’s
own. UI changes between units restore nowhere: they are not history, which is what
makes “select A, move it, select B, move it, undo” land on A (the state as it stood
when A’s move sealed) rather than on B.
restore must not write a watched store (that would fork history from inside a
replay); write plain signals. A unit sealed before this call carries no snapshot and
restores nothing.