Struct shrs_utils::cursor_buffer::CursorBuffer

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

Friendly wrapper around Rope data structure

Implementations§

source§

impl CursorBuffer

source

pub fn from_text(text: &str) -> Self

Create new CursorBuffer from string and sets cursor location to beginning

source

pub fn move_cursor(&mut self, loc: Location) -> Result<()>

Move the cursor using a location selector

source

pub fn move_cursor_clamp(&mut self, _loc: Location)

Move the cursor using a location selector, clamping the cursor if it were to move to invalid position

source

pub fn insert(&mut self, loc: Location, text: &str) -> Result<()>

Insert text and advance cursor to after the text inserted

source

pub fn insert_inplace(&mut self, loc: Location, text: &str) -> Result<()>

Insert text and offset cursor to point to same text

source

pub fn delete(&mut self, start: Location, end: Location) -> Result<()>

Delete a length of text starting from location and move cursor to start of deleted text

source

pub fn location_slice( &mut self, start: Location, end: Location ) -> Result<RopeSlice<'_>>

source

pub fn delete_inplace(&mut self, _loc: Location, _len: usize) -> Result<()>

Delete a length of text starting from location and offset the cursor accordingly such that it points to the same text

In the case that cursor was pointing at deleted text, the behavior is the same as delete

source

pub fn delete_before(&mut self, start: Location, end: Location) -> Result<()>

Delete a length of text ending at location

source

pub fn clear(&mut self)

Empties all text and resets cursor

source

pub fn slice<R>(&self, char_range: R) -> RopeSlice<'_>
where R: RangeBounds<usize>,

Get a slice of the text

source

pub fn chars(&self, loc: Location) -> Result<Chars<'_>>

Create forward iterator of chars from a location

source

pub fn cursor(&self) -> usize

Getter for the current index of the cursor

source

pub fn len(&self) -> usize

Get the length of the text in number of characters

source

pub fn is_empty(&self) -> bool

Check whether the buffer is empty

source

pub fn char_at(&self, loc: Location) -> Option<char>

Get char at position

source

pub fn rope(&self) -> &Rope

Get reference to underlying rope structure

source

pub fn to_absolute(&self, loc: Location) -> Result<usize>

Converts Location to an absolute index into the buffer. Performs bounds checking

source

pub fn as_str(&self) -> Cow<'_, str>

Get borrowed contents of CursorBuffer as a string

Trait Implementations§

source§

impl Default for CursorBuffer

source§

fn default() -> Self

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