pub struct EditHistory { /* private fields */ }Expand description
Bounded undo / redo history.
The maximum number of entries on each stack is configurable via
EditHistory::with_max. When the undo stack exceeds the limit the
oldest entry is discarded (FIFO eviction).
Implementations§
Source§impl EditHistory
impl EditHistory
Sourcepub fn apply(&mut self, txn: &EditTransaction, buffer: &mut TextBuffer)
pub fn apply(&mut self, txn: &EditTransaction, buffer: &mut TextBuffer)
Apply a pre-built EditTransaction to buffer, record it in the
undo stack, and clear the redo stack (any previously undone work is
forked away).
Sourcepub fn apply_edit(
&mut self,
buffer: &mut TextBuffer,
range: Range<usize>,
new_text: &str,
)
pub fn apply_edit( &mut self, buffer: &mut TextBuffer, range: Range<usize>, new_text: &str, )
Convenience: build a single-edit transaction, apply it, and record it.
old_text is captured automatically from the buffer.
Sourcepub fn undo(&mut self, buffer: &mut TextBuffer) -> bool
pub fn undo(&mut self, buffer: &mut TextBuffer) -> bool
Undo the most recent transaction, returning true if an undo was
performed.
Sourcepub fn redo(&mut self, buffer: &mut TextBuffer) -> bool
pub fn redo(&mut self, buffer: &mut TextBuffer) -> bool
Redo the most recently undone transaction, returning true if a redo
was performed.
Sourcepub fn record(&mut self, txn: EditTransaction)
pub fn record(&mut self, txn: EditTransaction)
Record a pre-built EditTransaction in the undo stack without
applying it to the buffer. This is useful when the caller has already
mutated the buffer (or is about to) and just needs the history entry.
Clears the redo stack and evicts the oldest entry when the stack
exceeds max_entries.
Sourcepub fn pop_undo(&mut self) -> Option<EditTransaction>
pub fn pop_undo(&mut self) -> Option<EditTransaction>
Pop the most recent transaction from the undo stack.
Returns None if the undo stack is empty. The caller is responsible
for applying the inverse and pushing a matching entry onto the redo
stack via push_redo.
Sourcepub fn pop_redo(&mut self) -> Option<EditTransaction>
pub fn pop_redo(&mut self) -> Option<EditTransaction>
Pop the most recent transaction from the redo stack.
Returns None if the redo stack is empty. The caller is responsible
for re-applying the edits and pushing a matching entry onto the undo
stack via push_undo.
Sourcepub fn push_redo(&mut self, txn: EditTransaction)
pub fn push_redo(&mut self, txn: EditTransaction)
Push a transaction onto the redo stack (used by external undo logic).
Sourcepub fn push_undo(&mut self, txn: EditTransaction)
pub fn push_undo(&mut self, txn: EditTransaction)
Push a transaction onto the undo stack without clearing the redo stack (used by external redo logic that manually manages both stacks).
Sourcepub fn undo_depth(&self) -> usize
pub fn undo_depth(&self) -> usize
Number of entries currently on the undo stack.
Sourcepub fn redo_depth(&self) -> usize
pub fn redo_depth(&self) -> usize
Number of entries currently on the redo stack.
Sourcepub fn max_entries(&self) -> usize
pub fn max_entries(&self) -> usize
Maximum entries per stack.
Trait Implementations§
Source§impl Clone for EditHistory
impl Clone for EditHistory
Source§fn clone(&self) -> EditHistory
fn clone(&self) -> EditHistory
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more