Skip to main content

Cursor

Struct Cursor 

Source
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: Position

Current 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

Source

pub const fn new(position: Position) -> Self

Create a new cursor at the given position.

Source

pub const fn origin() -> Self

Create a cursor at the origin (0, 0).

Source

pub const fn start_selection(&mut self)

Start a selection at the current position.

Source

pub const fn clear_selection(&mut self)

Clear the current selection.

Source

pub const fn has_selection(&self) -> bool

Check if a selection is active.

Source

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

Source

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.

Source

pub const fn clear_preferred_column(&mut self)

Clear preferred column.

Call this after horizontal movements that should reset the vertical movement target.

Source

pub fn effective_column(&self) -> usize

Get the effective column for vertical movement.

Returns the preferred column if set, otherwise the current column.

Trait Implementations§

Source§

impl Clone for Cursor

Source§

fn clone(&self) -> Cursor

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 Cursor

Source§

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

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

impl Default for Cursor

Source§

fn default() -> Cursor

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Cursor

Source§

fn eq(&self, other: &Cursor) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Cursor

Source§

impl Eq for Cursor

Source§

impl StructuralPartialEq for Cursor

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