pub struct History { /* private fields */ }Expand description
A bounded undo and redo history. See the module docs.
Implementations§
Source§impl History
impl History
Sourcepub fn set_limit(&mut self, limit: usize)
pub fn set_limit(&mut self, limit: usize)
Change the bound, dropping the oldest undo entries and the farthest redo entries beyond it.
Sourcepub fn undo_len(&self) -> usize
pub fn undo_len(&self) -> usize
Entries History::undo can step back through.
Sourcepub fn redo_len(&self) -> usize
pub fn redo_len(&self) -> usize
Entries History::redo can step forward through.
Sourcepub fn can_undo(&self) -> bool
pub fn can_undo(&self) -> bool
Whether History::undo has an entry.
Sourcepub fn can_redo(&self) -> bool
pub fn can_redo(&self) -> bool
Whether History::redo has an entry.
Sourcepub fn push(&mut self, inverse: Inverse)
pub fn push(&mut self, inverse: Inverse)
Keep inverse as the newest undo entry and clear redo.
Ignored when the history is disabled or the inverse is empty. If the inverse began at a revision the history does not describe, the old entries are dropped first.
Sourcepub fn track<T>(
&mut self,
model: &mut Model,
change: impl FnOnce(&mut Model) -> T,
) -> T
pub fn track<T>( &mut self, model: &mut Model, change: impl FnOnce(&mut Model) -> T, ) -> T
Run change on model and keep the inverse of what it wrote as one
entry.
Whatever change wrote is kept whether it returned Ok or Err;
nothing is rolled back. With a limit of 0 the change runs unrecorded.
Sourcepub fn peek_undo(&self, model: &Model) -> Result<Restored, HistoryError>
pub fn peek_undo(&self, model: &Model) -> Result<Restored, HistoryError>
What History::undo would change, without changing it.
Sourcepub fn peek_redo(&self, model: &Model) -> Result<Restored, HistoryError>
pub fn peek_redo(&self, model: &Model) -> Result<Restored, HistoryError>
What History::redo would change, without changing it.
Sourcepub fn undo(&mut self, model: &mut Model) -> Result<Restored, HistoryError>
pub fn undo(&mut self, model: &mut Model) -> Result<Restored, HistoryError>
Undo the newest entry.
Sourcepub fn rollback(&mut self, model: &mut Model) -> Result<Restored, HistoryError>
pub fn rollback(&mut self, model: &mut Model) -> Result<Restored, HistoryError>
Undo the newest entry and forget it: the model changes exactly as
History::undo changes it, with the same revision check and the
same refusals (the history is unchanged on a refusal), but the entry
is dropped instead of moved to the redo stack.
For a change that is abandoned, not undone by the user. Redo is
cleared, as History::push clears it: the model moved to a state
the redo entries were not recorded against, so redoing them would
replay onto the wrong base. In the usual case (the newest entry just
tracked) redo was empty already and stays empty.