pub struct Cursor {
    pub start: Pos,
    pub end: Option<Pos>,
}
Expand description

A cursor is a selection of text. It has a start and end position of the selection.

Fields§

§start: Pos

The start position of the selection. The start position is the origin of the selection, not necessarily the first position.

§end: Option<Pos>

The end position of the selection. If the end position is None, the cursor is a caret.

Implementations§

source§

impl Cursor

source

pub fn from_start(pos: Pos) -> Self

Create a new cursor with the given start position.

source

pub fn new(start: Pos, end: Pos) -> Self

Create a new cursor with the given start and end position.

source

pub fn move_cursor(&mut self, f: impl FnOnce(&mut Pos), shift: bool)

Move the cursor position. If shift is true, the end position will be moved instead of the start position.

source

pub fn delete_selection<T: Text + ?Sized>( &mut self, text: &mut impl TextEditable<T> )

Delete the currently selected text and update the cursor position.

source

pub fn handle_input<T: Text + ?Sized>( &mut self, code: &Code, key: &Key, modifiers: &Modifiers, text: &mut impl TextEditable<T>, max_text_length: usize )

Handle moving the cursor with the given key.

source

pub fn with_end(&mut self, f: impl FnOnce(&mut Pos))

Modify the end selection position

source

pub fn first(&self) -> &Pos

Returns first position of the selection (this could be the start or the end depending on the position)

source

pub fn last(&self) -> &Pos

Returns last position of the selection (this could be the start or the end depending on the position)

source

pub fn selection_len(&self, text: &(impl Text + ?Sized)) -> usize

Returns the length of the selection

Trait Implementations§

source§

impl Clone for Cursor

source§

fn clone(&self) -> Cursor

Returns a copy 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() -> Self

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

impl PartialEq<Cursor> for Cursor

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Cursor

source§

impl StructuralEq for Cursor

source§

impl StructuralPartialEq for Cursor

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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> CloneAny for Twhere T: Any + Clone,