pub struct Cursor {
pub position: Position,
pub anchor: Option<Position>,
pub preferred_column: Option<usize>,
}Expand description
Cursor state within a buffer.
The cursor tracks the current position, an optional selection anchor, and a preferred column for vertical movement.
§Selection
When anchor is Some, a selection extends from anchor to position.
The selection can be in either direction (anchor before or after position).
§Preferred Column
When moving vertically through lines of varying lengths, the cursor
attempts to maintain its horizontal position. The preferred_column
stores this target column.
§Example
use reovim_kernel::api::v1::*;
let mut cursor = Cursor::new(Position::new(0, 5));
// Start a selection
cursor.start_selection();
cursor.position = Position::new(0, 10);
// Get normalized bounds (start before end)
let (start, end) = cursor.selection_bounds().unwrap();
assert_eq!(start, Position::new(0, 5));
assert_eq!(end, Position::new(0, 10));Fields§
§position: PositionCurrent cursor position.
anchor: Option<Position>Selection anchor (if selection is active).
When Some, a selection extends from anchor to position.
preferred_column: Option<usize>Preferred column for vertical movement (j/k).
This preserves horizontal position when navigating through lines of varying lengths.
Implementations§
Source§impl Cursor
impl Cursor
Sourcepub const fn start_selection(&mut self)
pub const fn start_selection(&mut self)
Start a selection at the current position.
Sourcepub const fn clear_selection(&mut self)
pub const fn clear_selection(&mut self)
Clear the current selection.
Sourcepub const fn has_selection(&self) -> bool
pub const fn has_selection(&self) -> bool
Check if a selection is active.
Sourcepub fn selection_bounds(&self) -> Option<(Position, Position)>
pub fn selection_bounds(&self) -> Option<(Position, Position)>
Get the selection bounds (start, end) in document order.
Returns None if no selection is active.
The returned positions are always ordered (start <= end).
Sourcepub const fn update_preferred_column(&mut self)
pub const fn update_preferred_column(&mut self)
Set preferred column to current column.
Call this after horizontal movements to update the target column for subsequent vertical movements.
Sourcepub const fn clear_preferred_column(&mut self)
pub const fn clear_preferred_column(&mut self)
Clear preferred column.
Call this after horizontal movements that should reset the vertical movement target.
Sourcepub fn effective_column(&self) -> usize
pub fn effective_column(&self) -> usize
Get the effective column for vertical movement.
Returns the preferred column if set, otherwise the current column.