Struct modalkit::editing::rope::EditRope

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

A rope with context-aware movements and high-level operations.

Implementations§

source§

impl EditRope

source

pub fn empty() -> EditRope

Create an empty, zero-length rope.

source

pub fn write_to<T: Write>(&self, writer: T) -> Result<(), Error>

Write the contents of the EditRope to a writer.

source

pub fn split( &self, CharOff: CharOff, CharOff: CharOff, inclusive: bool ) -> (EditRope, EditRope, EditRope)

Split the rope into three different parts.

source

pub fn trim_start(&self) -> EditRope

Remove leading whitespace from the rope.

source

pub fn trim_end(&self) -> EditRope

Remove trailing whitespace from the rope.

source

pub fn trim_start_matches<F>(&self, matches: F) -> EditRope
where F: Fn(char) -> bool,

Remove matching leading characters from the rope.

source

pub fn trim_end_matches<F>(&self, matches: F) -> EditRope
where F: Fn(char) -> bool,

Remove matching trailing characters from the rope.

source

pub fn trim(&self) -> EditRope

Remove whitespace from the start and end of the rope.

source

pub fn slice<R: RangeBounds<CharOff>>(&self, range: R) -> EditRope

Returns a slice of a range within the rope.

source

pub fn replace<R: RangeBounds<CharOff>>( &mut self, range: R, substitution: EditRope ) -> (CursorChoice, Vec<CursorAdjustment>)

Replace a range within the rope with some new text.

source

pub fn repeat(&self, shape: TargetShape, times: usize) -> EditRope

Return the rope repeated n times.

source

pub fn transform( &self, start: CharOff, end: CharOff, inclusive: bool, f: impl Fn(EditRope) -> EditRope ) -> EditRope

Transform a range within the rope with function f, and return the updated version.

source

pub fn changecase(&self, case: &Case) -> EditRope

Change the case of this rope.

source

pub fn insert( &mut self, cursor: &Cursor, dir: MoveDir1D, text: EditRope, style: InsertStyle ) -> (CursorChoice, Vec<CursorAdjustment>)

Insert or replace text before or after a given cursor position.

source

pub fn paste( &mut self, cursor: &Cursor, dir: MoveDir1D, text: EditRope, shape: TargetShape ) -> (CursorChoice, Vec<CursorAdjustment>)

Paste text at a given cursor position.

source

pub fn trailing_newline(&mut self)

Mutably force this rope to contain a trailing newline if it doesn’t already.

source

pub fn get_line(&self, line: usize) -> Option<EditRope>

Get the text for a line.

source

pub fn get_char_at_cursor(&self, cursor: &Cursor) -> Option<char>

Returns the character (if it exists) at a given cursor position.

source

pub fn is_blank(&self) -> bool

Returns true if this rope contains only whitespace characters.

source

pub fn is_blank_line(&self, line: usize) -> bool

Returns true if a line contains only whitespace characters.

source

pub fn is_blank_range(&self, start: CharOff, end: CharOff) -> bool

Returns true if the inclusive range of bytes contains only whitespace characters.

source

pub fn len_offset(&self) -> CharOff

Return the length in number of characters as a CharOff.

source

pub fn len(&self) -> usize

Return the length in number of characters.

source

pub fn is_empty(&self) -> bool

Indicates whether or not this rope is empty (contains no characters).

source

pub fn get_lines(&self) -> usize

Return the number of lines in this rope.

source

pub fn line_after(&self, line: usize) -> Option<CharOff>

Get the character offset of the start of the following line.

source

pub fn get_columns(&self, line: usize) -> usize

Return the number of columns on the given line.

source

pub fn line_of_offset(&self, off: CharOff) -> usize

Return the line number of the given character offset.

source

pub fn offset_of_line(&self, line: usize) -> CharOff

Return the character offset of the start of a given line.

source

pub fn offset_to_cursor(&self, off: CharOff) -> Cursor

Convert a character offset to a Cursor.

source

pub fn cursor_to_offset(&self, cursor: &Cursor) -> CharOff

Convert a cursor to a character offset.

source

pub fn first(&self) -> Cursor

Return a cursor located at the first character in the rope.

source

pub fn last_offset(&self) -> CharOff

Return the last character offset in the rope.

source

pub fn last(&self) -> Cursor

Return a cursor located at the last character in the rope.

source

pub fn diff(&self, other: &EditRope) -> Vec<CursorAdjustment>

Compare this rope with a new version, and return a vector of adjustments needed to fix cursors and marks when moving to the new version.

source

pub fn newlines(&self, offset: CharOff) -> NewlineIterator<'_>

Returns an iterator over the newlines within this rope following offset.

source

pub fn chars(&self, pos: CharOff) -> CharacterIterator<'_>

Returns an iterator over the characters within this rope following position.

source

pub fn chars_until(&self, pos: CharOff, end: CharOff) -> CharacterIterator<'_>

Returns an iterator over the characters within this rope following position.

source

pub fn get_prefix_word_mut( &self, cursor: &mut Cursor, style: &WordStyle ) -> Option<Self>

Get the text before the cursor, and update the cursor to point to its start.

source

pub fn get_prefix_word( &self, cursor: &Cursor, style: &WordStyle ) -> Option<Self>

Get the text before the cursor.

source

pub fn get_cursor_word_mut( &self, cursor: &mut Cursor, style: &WordStyle ) -> Option<Self>

Returns the word underneath the Cursor, and updates it to point at the beginning of the word.

If the cursor is not positioned over a word, this will search for the next word in the text.

source

pub fn get_cursor_word( &self, cursor: &Cursor, style: &WordStyle ) -> Option<Self>

Returns the word underneath the Cursor.

If the cursor is not positioned over a word, this will search for the next word in the text.

Trait Implementations§

source§

impl Add for EditRope

§

type Output = EditRope

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
source§

impl AddAssign for EditRope

source§

fn add_assign(&mut self, rhs: EditRope)

Performs the += operation. Read more
source§

impl Clone for EditRope

source§

fn clone(&self) -> EditRope

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 CursorMovements<Cursor> for EditRope

source§

fn range_of_movement( &self, cursor: &Cursor, movement: &MoveType, count: &Count, ctx: &CursorMovementsContext<'_, Cursor> ) -> Option<EditRange<Cursor>>

Given an action’s movement, calculate the affected range base on the cursor’s current position.

source§

fn first_word( &self, cursor: &Cursor, _: &CursorMovementsContext<'_, Cursor> ) -> Cursor

Calculate the position of the first word on the line of the provided cursor.
source§

fn movement( &self, cursor: &Cursor, movement: &MoveType, count: &Count, ctx: &CursorMovementsContext<'_, Cursor> ) -> Option<Cursor>

Calculate the position of the cursor after performing a movement.
source§

fn range( &self, cursor: &Cursor, range: &RangeType, inclusive: bool, count: &Count, ctx: &CursorMovementsContext<'_, Cursor> ) -> Option<EditRange<Cursor>>

Calculate a cursor range based on a given cursor position and a RangeType.
source§

impl CursorSearch<Cursor> for EditRope

source§

fn find_char( &self, cursor: &Cursor, inclusive: bool, dir: MoveDir1D, multiline: bool, needle: char, count: usize ) -> Option<Cursor>

Search for a specific character.
source§

fn find_matches( &self, start: &Cursor, end: &Cursor, needle: &Regex ) -> Vec<EditRange<Cursor>>

Find matches for a regular expression within a range.
source§

fn find_regex( &self, cursor: &Cursor, dir: MoveDir1D, needle: &Regex, count: usize ) -> Option<EditRange<Cursor>>

Search for a regular expression.
source§

impl Debug for EditRope

source§

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

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

impl<'a> From<&'a EditRope> for Cow<'a, str>

source§

fn from(s: &'a EditRope) -> Self

Converts to this type from the input type.
source§

impl From<&str> for EditRope

source§

fn from(s: &str) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Cow<'a, str>> for EditRope

source§

fn from(s: Cow<'a, str>) -> Self

Converts to this type from the input type.
source§

impl From<EditRope> for RegisterCell

source§

fn from(s: EditRope) -> RegisterCell

Converts to this type from the input type.
source§

impl From<String> for EditRope

source§

fn from(s: String) -> Self

Converts to this type from the input type.
source§

impl From<char> for EditRope

source§

fn from(c: char) -> Self

Converts to this type from the input type.
source§

impl PartialEq<&str> for EditRope

source§

fn eq(&self, other: &&str) -> 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 PartialEq for EditRope

source§

fn eq(&self, other: &Self) -> 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 ToString for EditRope

source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl Eq for EditRope

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> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

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

source§

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

Checks if this value is equivalent to the given key. Read more
source§

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

source§

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

Compare self to key and return true if they are equal.
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,

§

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.
source§

impl<T> Any for T
where T: Any,

source§

impl<T> CloneAny for T
where T: Any + Clone,

source§

impl<T> CloneAnySend for T
where T: Any + Send + Clone,

source§

impl<T> CloneAnySendSync for T
where T: Any + Send + Sync + Clone,

source§

impl<T> CloneAnySync for T
where T: Any + Sync + Clone,