Struct Selection

Source
pub struct Selection { /* private fields */ }
Expand description

A cursor in the text file. This is an editing cursor, -(not a printing cursor.

Implementations§

Source§

impl Selection

Source

pub fn move_to(&mut self, p: Point, text: &Text)

Moves to specific, pre calculated Point.

Source

pub fn move_hor(&mut self, by: i32, text: &Text) -> i32

Internal horizontal movement function.

Returns the number of distance moved through.

Source

pub fn move_ver( &mut self, by: i32, text: &Text, area: &impl RawArea, cfg: PrintCfg, ) -> i32

Internal vertical movement function.

Returns the distance moved in lines.

Source

pub fn move_ver_wrapped( &mut self, by: i32, text: &Text, area: &impl RawArea, cfg: PrintCfg, ) -> i32

Internal vertical movement function.

Returns the distance moved in wrapped lines.

Source

pub fn set_anchor(&mut self)

Sets the position of the anchor to be the same as the current cursor position in the file

The anchor and current act as a range of text on the file.

Source

pub fn unset_anchor(&mut self) -> Option<Point>

Unsets the anchor

This is done so the cursor no longer has a valid selection.

Source

pub fn swap_ends(&mut self)

Switches the position of the anchor and caret

Source

pub fn caret(&self) -> Point

Returns the cursor’s position on the screen

Source

pub fn anchor(&self) -> Option<Point>

The anchor of this Selection, if it exists

Source

pub fn byte(&self) -> usize

The byte (relative to the beginning of the file) of the caret. Indexed at 0

Source

pub fn char(&self) -> usize

The char (relative to the beginning of the file) of the caret. Indexed at 0

Source

pub fn line(&self) -> usize

The line of the caret. Indexed at 0.

Source

pub fn range(&self, text: &Text) -> Range<usize>

Returns the range between caret and anchor.

If anchor isn’t set, returns an empty range on caret.

A Selection’s range will also never include the last character in a Text, which must be a newline.

§Warning

This function will return the range that is supposed to be replaced, if self.is_inclusive(), this means that it will return one more byte at the end, i.e. start..=end.

Source

pub fn start(&self) -> Point

The starting Point of this Selection

Source

pub fn end(&self, text: &Text) -> Point

The ending Point of this Selection

Source

pub fn point_range(&self, text: &Text) -> [Point; 2]

Returns the range between target and anchor.

like Selection::range, this function will not include beyond the last character’s Point.

If anchor isn’t set, returns an empty range on target.

Source

pub fn set_desired_cols(&mut self, v: usize, w: usize)

Sets both the desired visual column, as well as the desired wrapped column

Source

pub fn v_caret(&self, text: &Text, area: &impl RawArea, cfg: PrintCfg) -> VPoint

The visual caret of this Selection

VPoints include a lot more information than regular Points, like visual distance form the left edge, what the desired distance is, etc.

Source

pub fn v_anchor( &self, text: &Text, area: &impl RawArea, cfg: PrintCfg, ) -> Option<VPoint>

The visual anchor of this Selection, if it exists

VPoints include a lot more information than regular Points, like visual distance form the left edge, what the desired distance is, etc.

Source

pub fn v_range( &self, text: &Text, area: &impl RawArea, cfg: PrintCfg, ) -> [VPoint; 2]

The visual range between the caret and anchor of this Selection

VPoints include a lot more information than regular Points, like visual distance form the left edge, what the desired distance is, etc.

Trait Implementations§

Source§

impl<'__de, __Context> BorrowDecode<'__de, __Context> for Selection

Source§

fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given BorrowDecode.
Source§

impl Clone for Selection

Source§

fn clone(&self) -> Selection

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 Selection

Source§

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

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

impl<__Context> Decode<__Context> for Selection

Source§

fn decode<__D: Decoder<Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
Source§

impl Default for Selection

Source§

fn default() -> Selection

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

impl Encode for Selection

Source§

fn encode<__E: Encoder>(&self, encoder: &mut __E) -> Result<(), EncodeError>

Encode a given type.

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.