pub struct DocumentHistory { /* private fields */ }Expand description
Undo/redo history for a document.
Changes are pushed as they are applied — prefer
push_applied with the result of
DocumentChange::try_apply, so the recorded undo evidence is derived
from the document rather than caller-authored. undo
returns the inverse of the most-recent change; redo
re-applies a change that was undone.
Implementations§
Source§impl DocumentHistory
impl DocumentHistory
Sourcepub fn push_applied(&mut self, applied: &AppliedChange)
pub fn push_applied(&mut self, applied: &AppliedChange)
Records a verified change. Any future (redo) stack is cleared.
The forward change is reconstructed from the applied change’s derived inverse, so both undo and redo evidence come from the document itself.
Sourcepub fn push(&mut self, change: DocumentChange)
pub fn push(&mut self, change: DocumentChange)
Records a new change. Any future (redo) stack is cleared.
The change’s old_text is trusted as-is; prefer
push_applied, which records evidence derived
from the document.
Sourcepub fn undo(&mut self) -> Option<&DocumentChange>
pub fn undo(&mut self) -> Option<&DocumentChange>
Removes the most-recent change from the undo stack and returns a
reference to it, or None if the stack is empty.
The inverse of the returned change is placed on the redo stack.
Sourcepub fn redo(&mut self) -> Option<&DocumentChange>
pub fn redo(&mut self) -> Option<&DocumentChange>
Re-applies the most-recently-undone change and returns a reference
to it, or None if the redo stack is empty.