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):
initializedis false- First
resolve_with_sessioncall readspending_count/pending_registerfrom VimSessionState - Sets
initialized = true - Subsequent keys use the cached state
- When mode is popped or cancelled,
reset()clears the state
Fields§
§operator: OperatorTypeThe 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: KeySequenceAccumulated key sequence for multi-key motions.
initialized: boolWhether 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
impl OperatorState
Sourcepub fn new(operator: OperatorType) -> Self
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.
Sourcepub fn with_context(
operator: OperatorType,
count: Option<usize>,
register: Option<char>,
) -> Self
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.
Sourcepub fn set_start_position(&mut self, pos: Position)
pub fn set_start_position(&mut self, pos: Position)
Set the start position.
Sourcepub fn effective_count(&self) -> usize
pub fn effective_count(&self) -> usize
Get the effective count (operator_count * motion_count, defaulting to 1).
Sourcepub fn explicit_count(&self) -> Option<usize>
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 line1G(count=1) → line 1
Sourcepub fn has_motion_count(&self) -> bool
pub fn has_motion_count(&self) -> bool
Check if we have a motion count.
Sourcepub fn accumulate_motion_count(&mut self, key: &KeyEvent)
pub fn accumulate_motion_count(&mut self, key: &KeyEvent)
Accumulate a motion count digit.
Sourcepub fn take_motion_count(&mut self) -> Option<usize>
pub fn take_motion_count(&mut self) -> Option<usize>
Take the motion count, clearing it.
Sourcepub fn keys(&self) -> KeySequence
pub fn keys(&self) -> KeySequence
Get a clone of pending keys.
Sourcepub fn clear_keys(&mut self)
pub fn clear_keys(&mut self)
Clear pending keys.
Trait Implementations§
Source§impl Clone for OperatorState
impl Clone for OperatorState
Source§fn clone(&self) -> OperatorState
fn clone(&self) -> OperatorState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more