Skip to main content

UndoTree

Struct UndoTree 

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

The full per-buffer undo history.

The tree is append-only (groups never disappear from groups once recorded; the history-cap policy is implemented by snapshotting the content and dropping covered edit rows at the persistence layer).

Implementations§

Source§

impl UndoTree

Source

pub fn new() -> Self

An empty tree (current = pre-history).

Source

pub fn restore(groups: Vec<UndoGroup>, current: Option<UndoGroupId>) -> Self

Rebuild a tree from previously recorded groups and a head pointer.

Distinct from replaying Self::insert_group per group: that call re-parents a None parent onto whatever the head currently is, which silently re-roots every root-level branch onto the group inserted before it. A restore has to preserve the recorded shape exactly, so it takes the groups as given. Unknown current ids fall back to pre-history rather than panicking, because the input crossed a serialization boundary and is not a caller invariant.

Source

pub fn insert_group( &mut self, id: UndoGroupId, parent: Option<UndoGroupId>, timestamp_ms: i64, command: impl Into<String>, )

Insert an empty group rooted at parent (or at the current head if parent is None and a current group exists). Returns the group’s stable id.

Used both at edit time (when the engine mints a new group) and at recovery time (when persisted rows are replayed).

Source

pub fn append_record(&mut self, group_id: UndoGroupId, record: EditRecord)

Append an edit record to the named group. Touches current to point at that group.

§Panics

Panics if group_id is unknown (caller-bug only — the core thread always inserts the group before recording into it).

Source

pub fn is_empty(&self) -> bool

True when no groups have been recorded.

Source

pub fn len(&self) -> usize

Number of groups in the tree.

Source

pub fn group_count(&self) -> usize

Number of UndoGroups recorded. Alias for Self::len, surfaced separately because the trace stream emits undo_tree_groups= and undo_tree_records= side by side.

Source

pub fn record_count(&self) -> usize

Total number of EditRecords across every group. Bumped by every Self::append_record call; combined with Self::byte_size_estimate this lets the memory_breakdown line report bytes-per-record so Block 4.1 can prove its SmallVec<[Selection; 1]> rewrite shrank per-record overhead.

Source

pub fn byte_size_estimate(&self) -> usize

Estimated heap bytes retained by the undo tree.

Source

pub fn current(&self) -> Option<&UndoGroup>

The currently-applied group, if any.

Source

pub fn current_id(&self) -> Option<UndoGroupId>

Id of the currently-applied group.

Source

pub fn get(&self, id: UndoGroupId) -> Option<&UndoGroup>

Borrow a group by id.

Source

pub fn groups(&self) -> &[UndoGroup]

Borrow every group in insertion order. Used by the picker UI.

Source

pub fn set_current(&mut self, id: Option<UndoGroupId>)

Step the current pointer to id, asserting the group exists.

§Panics

Panics if id is unknown — the call sites compute targets only from existing groups, so this is a structural invariant.

Source

pub fn group_to_undo(&self) -> Option<&UndoGroup>

The group that an editor.undo from the current head would revert, i.e. the current group itself.

Source

pub fn group_to_redo(&self) -> Option<&UndoGroup>

The group that an editor.redo from the current head would re-apply — the most-recently-recorded direct child of the current head (or of the pre-history root if current is None).

The “most recent” tie-breaker matches the user’s most recent intent: if you undo and then redo, you redo the branch you just left.

Source

pub fn group_to_redo_alternate(&self) -> Option<&UndoGroup>

An alternate redo target: a child of the current pointer that is not the one Self::group_to_redo would pick. Returns None when the current pointer has fewer than two children.

Used to step through fork branches after the user has undone past the divergence point.

Source

pub fn children(&self, parent: Option<UndoGroupId>) -> Vec<&UndoGroup>

Direct children of parent in insertion order (oldest first). parent = None returns the root-level branches.

Trait Implementations§

Source§

impl Clone for UndoTree

Source§

fn clone(&self) -> Self

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 UndoTree

Source§

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

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

impl Default for UndoTree

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.