Skip to main content

MotionState

Struct MotionState 

Source
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

Source

pub const fn new() -> Self

Creates empty Normal-mode command state with no repeatable search.

Source

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.

Source

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.

Source

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.

Source

pub const fn is_awaiting_target(&self) -> bool

Reports whether a find or till target character is pending.

Source

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.

Source

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 ,.

Source

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.

Trait Implementations§

Source§

impl Debug for MotionState

Source§

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

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

impl Default for MotionState

Source§

fn default() -> MotionState

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> 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, 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.