pub struct Trail {
undo: Vec<Entry>,
redo: Vec<Entry>,
standing: Rev,
}Expand description
Where a session’s history stands: what one press would take back, what one would put back, and which rev’s document the head currently holds.
Fields§
§undo: Vec<Entry>§redo: Vec<Entry>§standing: RevImplementations§
Source§impl Trail
impl Trail
Sourcepub fn standing(&self) -> Rev
pub fn standing(&self) -> Rev
The rev whose document the head holds. An edit at N stands at N; a step stands at the rev it restored, so an undo and its redo return the session to the position it started from rather than to a rev that merely looks like it.
Sourcepub fn seeded(&mut self, rev: Rev)
pub fn seeded(&mut self, rev: Rev)
Stand at rev with nothing new to take back: a commit that is the
document’s past rather than a step this session took — the seeding
path, and a repo built by folding a log before a session opened
over it.
Without it the first edit over such a document would offer to restore the empty document, since that is where a fresh trail stands.
Sourcepub fn record(&mut self, rev: Rev, journal_as: JournalAs)
pub fn record(&mut self, rev: Rev, journal_as: JournalAs)
Take a record of rev into the trail: an edit or a redo is a step
somebody can take back, an undo is one they can put back, and each
step retires the entry it consumed.
This is the only place the policy lives, so a live session and a replayed log cannot disagree about the trail they end up with.
Sourcepub fn stepping(
&self,
edit: Rev,
direction: Direction,
) -> Result<Entry, UndoRefusal>
pub fn stepping( &self, edit: Rev, direction: Direction, ) -> Result<Entry, UndoRefusal>
The entry a step naming edit would take, without taking it.
§Errors
UndoRefusal::Spent when nothing stands ready, and
UndoRefusal::Stale — reporting its own top — when the top is a
different rev than edit.
pub fn can_undo(&self) -> bool
pub fn can_redo(&self) -> bool
Sourcepub fn undo_depth(&self) -> usize
pub fn undo_depth(&self) -> usize
How many steps stand ready to be taken back. The editor keeps a parallel stack that interleaves view steps with these, and the two depths must agree — exposed so the mismatch is checkable rather than silent.
pub fn redo_depth(&self) -> usize
Sourcepub fn next_undo(&self) -> Option<Rev>
pub fn next_undo(&self) -> Option<Rev>
The rev an undo would move, and the one a redo would — so a caller holding its own history can tell whether the step it is about to take is still the step this trail would take.
pub fn next_redo(&self) -> Option<Rev>
Sourcepub fn undo_revs(&self) -> Vec<Rev>
pub fn undo_revs(&self) -> Vec<Rev>
Every rev standing ready to be taken back, oldest first — for a caller whose own stack must agree with this one, entry for entry.
Sourcepub fn redo_revs(&self) -> Vec<Rev>
pub fn redo_revs(&self) -> Vec<Rev>
The forward half of Self::undo_revs.
Sourcepub fn standings(&self) -> Vec<Rev>
pub fn standings(&self) -> Vec<Rev>
Everywhere this trail can stand, deepest past first, with
Self::standing at index Self::undo_depth — one point per
step a walk from either end would take, which is what a session
rebuilding its own stack from a reopened document needs.