Skip to main content

EditHistory

Struct EditHistory 

Source
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

Source

pub fn new() -> Self

Create a history with the default max depth (1 000 entries).

Source

pub fn with_max(max_entries: usize) -> Self

Create a history with a custom maximum depth.

Source

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).

Source

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.

Source

pub fn undo(&mut self, buffer: &mut TextBuffer) -> bool

Undo the most recent transaction, returning true if an undo was performed.

Source

pub fn redo(&mut self, buffer: &mut TextBuffer) -> bool

Redo the most recently undone transaction, returning true if a redo was performed.

Source

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.

Source

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.

Source

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.

Source

pub fn push_redo(&mut self, txn: EditTransaction)

Push a transaction onto the redo stack (used by external undo logic).

Source

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).

Source

pub fn undo_depth(&self) -> usize

Number of entries currently on the undo stack.

Source

pub fn redo_depth(&self) -> usize

Number of entries currently on the redo stack.

Source

pub fn max_entries(&self) -> usize

Maximum entries per stack.

Source

pub fn clear(&mut self)

Discard all history.

Trait Implementations§

Source§

impl Clone for EditHistory

Source§

fn clone(&self) -> EditHistory

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EditHistory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EditHistory

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.