pub struct SnippetSession { /* private fields */ }Expand description
A live snippet session: one tracked range per stop, the active stop
AlwaysGrows and the rest NeverGrows. It never touches the document or
history — the caller inserts the snippet text (one sealed transaction),
selects the range this reports, and the session only registers / swaps /
unregisters ranges. Cancellation is never a transaction: text stays, ranges
unregister, nothing enters history.
Implementations§
Source§impl SnippetSession
impl SnippetSession
Sourcepub fn start(
snippet: &Snippet,
base: u32,
store: &mut DecorationStore,
) -> Option<(Self, Range<u32>)>
pub fn start( snippet: &Snippet, base: u32, store: &mut DecorationStore, ) -> Option<(Self, Range<u32>)>
Start a session from a just-inserted snippet whose stop ranges are offset
by base (the insert position). Registers one SnippetStop per stop
(the first AlwaysGrows, the rest NeverGrows) and returns the session
plus the first stop’s content for the caller to select. None — no
session — when the snippet has no stop besides the final.
Sourcepub fn active_index(&self) -> usize
pub fn active_index(&self) -> usize
The ordinal (visit-order) index of the active stop.
Sourcepub fn active_range(&self, store: &DecorationStore) -> Option<Range<u32>>
pub fn active_range(&self, store: &DecorationStore) -> Option<Range<u32>>
The active stop’s current content range (post-edit), or None if it was
dropped.
Sourcepub fn tab(&mut self, forward: bool, store: &mut DecorationStore) -> TabOutcome
pub fn tab(&mut self, forward: bool, store: &mut DecorationStore) -> TabOutcome
Tab (forward) / Shift+Tab (!forward) between stops. Swaps stickiness
on a move; Tab past the last non-final stop ends the session at the final
stop (TabOutcome::Finish, ranges already unregistered).
Sourcepub fn on_caret(
&mut self,
offset: u32,
store: &mut DecorationStore,
) -> CaretOutcome
pub fn on_caret( &mut self, offset: u32, store: &mut DecorationStore, ) -> CaretOutcome
A caret landed at offset (a click): re-activate a different stop it lands
in, stay if it’s the active stop, or report that it left every stop (the
caller then cancels).
Sourcepub fn edit_escapes(&self, range: &Range<u32>, store: &DecorationStore) -> bool
pub fn edit_escapes(&self, range: &Range<u32>, store: &DecorationStore) -> bool
Whether an edit spanning range lands wholly outside every stop (→ the
caller cancels). An edit touching any stop keeps the session.
Sourcepub fn cancel(&mut self, store: &mut DecorationStore)
pub fn cancel(&mut self, store: &mut DecorationStore)
Unregister every stop range. Cancellation is never a transaction.