pub struct MotionState { /* private fields */ }Expand description
Normal-mode state shared across configurable key adapters.
This type owns the Vim semantics of decimal counts, % and G count
reinterpretation, find/till character arguments, and ;/, repetition.
Terminal key events and application-specific bindings remain adapter
concerns. The state has no I/O and no caller-controlled panic path.
Implementations§
Source§impl MotionState
impl MotionState
Sourcepub const fn has_count(&self) -> bool
pub const fn has_count(&self) -> bool
Reports whether a non-zero decimal count has started.
A leading 0 is deliberately not a count; callers can bind it to
MotionKind::LineStart.
Sourcepub fn push_count_digit(&mut self, digit: char) -> bool
pub fn push_count_digit(&mut self, digit: char) -> bool
Adds an ASCII digit to the pending count with saturating arithmetic.
Returns false for non-digits and for a leading zero, which lets an
adapter interpret that key as Vim’s 0 motion instead. Once the parsed
value reaches usize::MAX, further digits keep it at that value.
Sourcepub fn take_count(&mut self) -> Option<usize>
pub fn take_count(&mut self) -> Option<usize>
Takes a pending count for a non-motion command such as jump history.
This does not cancel a pending character-argument motion or forget the last completed character search.
Sourcepub const fn is_awaiting_target(&self) -> bool
pub const fn is_awaiting_target(&self) -> bool
Reports whether a find or till target character is pending.
Sourcepub fn finish(&mut self, motion: Motion) -> MotionResolution
pub fn finish(&mut self, motion: Motion) -> MotionResolution
Completes a motion template using the current count and repeat state.
The pending count is always consumed. Vim-specific reinterpretations
happen here: counted % becomes a clamped buffer percentage, and
counted G/gg selects the supplied one-based line. Find/till motions
without a target return MotionResolution::AwaitingTarget; those with
a target immediately become the source for ; and , repetition.
While a target is pending, the caller must use Self::accept_target
or Self::reset_pending before submitting an unrelated command.
Sourcepub fn accept_target(&mut self, target: char) -> Option<Motion>
pub fn accept_target(&mut self, target: char) -> Option<Motion>
Supplies the character argument for a pending find or till motion.
Returns None when no motion is waiting. Any Unicode scalar is accepted;
whether it exists in the current line is decided when the motion is
applied. A completed motion becomes the source for ; and ,.
Sourcepub fn reset_pending(&mut self)
pub fn reset_pending(&mut self)
Cancels only the pending count and character argument.
The last completed character search remains available to ; and ,,
matching Vim when an unrelated or cancelled command follows it.