Struct rat_widget::textarea::core::InputCore

source ·
pub struct InputCore { /* private fields */ }
Expand description

Core for text editing.

Implementations§

source§

impl InputCore

source

pub fn new() -> Self

source

pub fn set_move_col(&mut self, col: Option<usize>)

Extra column information for cursor movement. The cursor position is capped to the current line length, so if you move up one row, you might end at a position left of the current column. If you move up once more you want to return to the original position. That’s what is stored here.

source

pub fn move_col(&mut self) -> Option<usize>

Extra column information for cursor movement.

source

pub fn set_cursor( &mut self, cursor: (usize, usize), extend_selection: bool, ) -> bool

Set the cursor position. The value is capped to the number of text lines and the line-width. Returns true, if the cursor actually changed.

source

pub fn cursor(&self) -> (usize, usize)

Cursor position.

source

pub fn anchor(&self) -> (usize, usize)

Selection anchor.

source

pub fn set_value<S: AsRef<str>>(&mut self, s: S)

Set the text. Resets the selection and any styles.

source

pub fn set_value_rope(&mut self, s: Rope)

Set the text value as a Rope. Resets all internal state.

source

pub fn value(&self) -> String

Text value.

source

pub fn value_range(&self, range: TextRange) -> Option<RopeSlice<'_>>

A range of the text as RopeSlice.

source

pub fn value_as_bytes(&self) -> Bytes<'_>

Value as Bytes iterator.

source

pub fn value_as_chars(&self) -> Chars<'_>

Value as Chars iterator.

source

pub fn clear_styles(&mut self)

Clear styles.

source

pub fn add_style(&mut self, range: TextRange, style: usize)

Add a style for the given range.

What is given here is the index into the Vec with the actual Styles. Those are set at the widget.

source

pub fn styles(&self) -> &[(TextRange, usize)]

Style map.

source

pub fn styles_at(&self, pos: (usize, usize), result: &mut Vec<usize>)

Finds all styles for the given position.

Returns the indexes into the style vec.

source

pub fn line(&self, n: usize) -> Option<RopeGraphemes<'_>>

Returns a line as an iterator over the graphemes for the line. This contains the \n at the end.

source

pub fn line_idx(&self, n: usize) -> Option<RopeGraphemesIdx<'_>>

Returns a line as an iterator over the graphemes for the line. This contains the \n at the end.

source

pub fn line_width(&self, n: usize) -> Option<usize>

Line width as grapheme count.

source

pub fn len_lines(&self) -> usize

Number of lines.

source

pub fn clear(&mut self) -> bool

Reset.

source

pub fn is_empty(&self) -> bool

Empty.

source

pub fn has_selection(&self) -> bool

Any text selection.

source

pub fn set_selection(&mut self, range: TextRange) -> bool

source

pub fn select_all(&mut self) -> bool

source

pub fn selection(&self) -> TextRange

Returns the selection as TextRange.

source

pub fn iter_scrolled(&self, offset: (usize, usize)) -> ScrolledIter<'_>

Iterate over the text, shifted by the offset.

source

pub fn next_word_boundary(&self, pos: (usize, usize)) -> Option<(usize, usize)>

Find next word.

source

pub fn prev_word_boundary(&self, pos: (usize, usize)) -> Option<(usize, usize)>

Find prev word.

source

pub fn len_chars(&self) -> usize

Len in chars

source

pub fn len_bytes(&self) -> usize

Len in bytes

source

pub fn char_pos(&self, char_pos: usize) -> Option<(usize, usize)>

Char position to grapheme position.

source

pub fn byte_pos(&self, byte: usize) -> Option<(usize, usize)>

Byte position to grapheme position.

source

pub fn byte_at(&self, pos: (usize, usize)) -> Option<(usize, usize)>

Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.

source

pub fn char_at(&self, pos: (usize, usize)) -> Option<usize>

Returns the first char position for the grapheme position.

source

pub fn insert_char(&mut self, pos: (usize, usize), c: char)

Insert a character.

source

pub fn insert_newline(&mut self, pos: (usize, usize))

Insert a line break.

source

pub fn remove(&mut self, range: TextRange)

Trait Implementations§

source§

impl Clone for InputCore

source§

fn clone(&self) -> InputCore

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 InputCore

source§

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

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

impl Default for InputCore

source§

fn default() -> InputCore

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

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.