Skip to main content

OperatorState

Struct OperatorState 

Source
pub struct OperatorState {
    pub operator: OperatorType,
    pub start_position: Option<Position>,
    pub operator_count: Option<usize>,
    pub motion_count: Option<usize>,
    pub register: Option<char>,
    pub pending_keys: KeySequence,
    pub initialized: bool,
}
Expand description

State owned by an operator resolver.

Unlike VimSessionState.pending_operator, this state is owned by the resolver itself. This makes testing easier and eliminates runtime lookup of operator type.

§State Lifecycle

When a mode is pushed (e.g., user presses ‘d’ in normal mode):

  1. initialized is false
  2. First resolve_with_session call reads pending_count/pending_register from VimSessionState
  3. Sets initialized = true
  4. Subsequent keys use the cached state
  5. When mode is popped or cancelled, reset() clears the state

Fields§

§operator: OperatorType

The type of operator (delete, yank, change).

§start_position: Option<Position>

Start position captured when entering operator mode.

§operator_count: Option<usize>

Count applied before the operator (e.g., 2d in 2dw).

§motion_count: Option<usize>

Count applied to the motion (e.g., 3 in d3w).

§register: Option<char>

Target register for the operation.

§pending_keys: KeySequence

Accumulated key sequence for multi-key motions.

§initialized: bool

Whether the state has been initialized with context from normal mode.

On first key press in the mode, the resolver reads pending_count and pending_register from VimSessionState and sets this to true.

Implementations§

Source§

impl OperatorState

Source

pub fn new(operator: OperatorType) -> Self

Create a new operator state.

The state starts uninitialized. On first key press, the resolver will read pending_count and pending_register from VimSessionState.

Source

pub fn with_context( operator: OperatorType, count: Option<usize>, register: Option<char>, ) -> Self

Create operator state with initial count and register.

Used in tests to pre-initialize state without going through VimSessionState.

Source

pub fn set_start_position(&mut self, pos: Position)

Set the start position.

Source

pub fn effective_count(&self) -> usize

Get the effective count (operator_count * motion_count, defaulting to 1).

Source

pub fn explicit_count(&self) -> Option<usize>

Get count only if explicitly specified (not defaulted).

Returns None if no count was given, Some(n) if count was given. This preserves the distinction between “no count” and “count=1” for motions like G/gg where these have different semantics:

  • G (no count) → last line
  • 1G (count=1) → line 1
Source

pub fn has_motion_count(&self) -> bool

Check if we have a motion count.

Source

pub fn accumulate_motion_count(&mut self, key: &KeyEvent)

Accumulate a motion count digit.

Source

pub fn take_motion_count(&mut self) -> Option<usize>

Take the motion count, clearing it.

Source

pub fn push_key(&mut self, key: KeyEvent)

Add a key to pending sequence.

Source

pub fn keys(&self) -> KeySequence

Get a clone of pending keys.

Source

pub fn clear_keys(&mut self)

Clear pending keys.

Source

pub fn reset(&mut self)

Reset all state for mode re-entry.

Called when the mode is exited (cancelled or completed). Clears all state including count and register so they can be re-read from VimSessionState on the next mode entry.

Trait Implementations§

Source§

impl Clone for OperatorState

Source§

fn clone(&self) -> OperatorState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OperatorState

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more