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
impl UndoTree
Sourcepub fn restore(groups: Vec<UndoGroup>, current: Option<UndoGroupId>) -> Self
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.
Sourcepub fn insert_group(
&mut self,
id: UndoGroupId,
parent: Option<UndoGroupId>,
timestamp_ms: i64,
command: impl Into<String>,
)
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).
Sourcepub fn append_record(&mut self, group_id: UndoGroupId, record: EditRecord)
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).
Sourcepub fn group_count(&self) -> usize
pub fn group_count(&self) -> usize
Sourcepub fn record_count(&self) -> usize
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.
Sourcepub fn byte_size_estimate(&self) -> usize
pub fn byte_size_estimate(&self) -> usize
Estimated heap bytes retained by the undo tree.
Sourcepub fn current_id(&self) -> Option<UndoGroupId>
pub fn current_id(&self) -> Option<UndoGroupId>
Id of the currently-applied group.
Sourcepub fn get(&self, id: UndoGroupId) -> Option<&UndoGroup>
pub fn get(&self, id: UndoGroupId) -> Option<&UndoGroup>
Borrow a group by id.
Sourcepub fn groups(&self) -> &[UndoGroup]
pub fn groups(&self) -> &[UndoGroup]
Borrow every group in insertion order. Used by the picker UI.
Sourcepub fn set_current(&mut self, id: Option<UndoGroupId>)
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.
Sourcepub fn group_to_undo(&self) -> Option<&UndoGroup>
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.
Sourcepub fn group_to_redo(&self) -> Option<&UndoGroup>
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.
Sourcepub fn group_to_redo_alternate(&self) -> Option<&UndoGroup>
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.