Skip to main content

History

Struct History 

Source
pub struct History { /* private fields */ }
Expand description

Whole-content undo history, stored as rope snapshots.

A snapshot is a Rope rather than a String because ropey clones are O(1) and copy-on-write: two snapshots share every node they have in common, so a deep undo stack over a large file costs the edits, not one full copy of the text per step. to_string() would allocate and copy the whole buffer on every keystroke.

Whole-content snapshots stay the right call at this size — they are correct for any edit shape, and with structural sharing they are no longer expensive enough to justify per-edit deltas.

Runs have no clock. VS Code and Zed break undo groups on an idle timer. A timer means the buffer needs a clock, which means tests need to inject one, which means the rule is only ever exercised through a fake. The rule here is structural instead: consecutive edits of the same EditKind coalesce, and anything that is not an edit — a motion, a click, a save — calls boundary. That is deterministic and it matches what a user means by “undo what I just typed”: the run ends when they moved.

ponytail: pausing mid-word for ten minutes without moving still coalesces. If that ever bites, a timer goes beside this rule, not instead of it.

Implementations§

Source§

impl History

Source

pub fn record(&mut self, kind: EditKind, before: Rope, selections: &Selections)

Record the state before an edit, unless it continues the open run.

Continuing a run means not pushing: the snapshot already on the stack predates the whole run, which is exactly the state undo should restore.

Source

pub fn boundary(&mut self)

End the open run, so the next edit starts a new undo step.

Called on anything that is not an edit — a motion, a click, a save.

Source

pub fn undo( &mut self, current: Rope, selections: &Selections, ) -> Option<Snapshot>

Returns the state to restore, banking current for redo.

Source

pub fn redo( &mut self, current: Rope, selections: &Selections, ) -> Option<Snapshot>

Trait Implementations§

Source§

impl Default for History

Source§

fn default() -> History

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