TextMut

Struct TextMut 

Source
pub struct TextMut<'t> { /* private fields */ }
Expand description

A struct that allows for Text modifications from the Widget::text_mut function

It is pretty much identical to &mut Text, the difference is that you can’t reassign it to a new Text. This is done in order to prevent radical changes to the Text of the Buffer from the outside.

Implementations§

Source§

impl<'t> TextMut<'t>

Source

pub fn replace_range(&mut self, range: impl TextRange, edit: impl ToString)

Replaces a range in the Text

§TextRange behavior:

If you give a single usize/Point, it will be interpreted as a range from.

Source

pub fn parts(self) -> TextParts<'t>

The parts that make up a Text

This function is used when you want to insert/remove Tags (i.e., borrow the inner InnerTags mutably via Tags), while still being able to read from the Bytes and Selections.

Source

pub fn insert_tag<I, R>( &mut self, tagger: Tagger, r: I, tag: impl Tag<I, R>, ) -> Option<R>
where R: Copy,

Inserts a Tag at the given position

Source

pub fn insert_tag_after<I, R>( &mut self, tagger: Tagger, r: I, tag: impl Tag<I, R>, ) -> Option<R>
where R: Copy,

Like insert_tag, but does it after other Tags with the same priority

Source

pub fn remove_tags( &mut self, taggers: impl Taggers, range: impl TextRangeOrIndex, )

Removes the Tags of a key from a region

§Caution

While it is fine to do this on your own widgets, you should refrain from using this function in a Buffers Text, as it must iterate over all tags in the buffer, so if there are a lot of other tags, this operation may be slow.

§TextRange behavior

If you give it a Point or usize, it will be treated as a one byte range.

Source

pub fn clear_tags(&mut self)

Removes all Tags

Refrain from using this function on Buffers, as there may be other Tag providers, and you should avoid messing with their tags.

Source

pub fn undo(&mut self)

Undoes the last moment, if there was one

Source

pub fn redo(&mut self)

Redoes the last moment in the history, if there is one

Source

pub fn new_moment(&mut self)

Finishes the current moment and adds a new one to the history

Source

pub fn selections_mut(self) -> &'t mut Selections

A mut reference to this Text’s Selections if they exist

Methods from Deref<Target = Text>§

Source

pub fn is_empty_empty(&self) -> bool

Whether the Bytes and InnerTags are empty

This ignores the last '\n' in the Text, since it is always there no matter what.

If you only want to check for the Bytes, ignoring possible Ghosts, see is_empty.

Source

pub fn bytes(&self) -> &Bytes

The inner bytes of the Text

Note that, since Text has an implementation of std::ops::Deref<Target = Bytes>, you mostly don’t need to call this method.

Source

pub fn indent(&self, p: Point, area: &Area, opts: PrintOpts) -> usize

Gets the indentation level on the current line

Source

pub fn ghost_max_points_at(&self, b: usize) -> TwoPoints

The maximum points in the atth byte

This point is essentially the point at that byte, plus the last possible Point of any Ghosts in that position.

Source

pub fn len_points(&self) -> TwoPoints

The points at the end of the text

This will essentially return the last point of the text, alongside the last possible Point of any Ghost at the end of the text.

Source

pub fn points_after(&self, tp: TwoPoints) -> Option<TwoPoints>

Points visually after the TwoPoints

If the TwoPoints in question is concealed, treats the next visible character as the first character, and returns the points of the next visible character.

This method is useful if you want to iterator reversibly right after a certain point, thus including the character of said point.

Source

pub fn visual_line_start(&self, points: TwoPoints, skip: usize) -> TwoPoints

The visual start of the line

This point is defined not by where the line actually begins, but by where the last ‘\n’ was located. For example, if Tags create ghost text or omit text from multiple different lines, this point may differ from where in the Text the real line actually begins.

The skip value is how many \n should be skipped before returning.

Source

pub fn get_ghost(&self, id: GhostId) -> Option<&Text>

Gets the Ghost of a given GhostId

Source

pub fn to_string(&self) -> String

Clones the inner Bytes as a String

This function will also cut out a final ‘\n’ from the string.

Source

pub fn has_unsaved_changes(&self) -> bool

Wether or not the content has changed since the last save

Returns true only if the actual bytes of the Text have been changed, ignoring Tags and all the other things, since those are not written to the filesystem.

Source

pub fn iter_fwd(&self, at: TwoPoints) -> FwdIter<'_>

A forward iterator of the chars and tags of the Text

Source

pub fn iter_rev(&self, at: TwoPoints) -> RevIter<'_>

A reverse iterator of the chars and tags of the Text

Source

pub fn tags_fwd( &self, b: usize, lookaround: Option<usize>, ) -> Peekable<Chain<FwdBoundsBefore<'_>, FwdTagsMapper<'_>>>

A forward iterator over the Tags of the Text

This iterator will consider some Tags before b, since their ranges may overlap with b

The amount of tags to look for behind depeds on the internal min_len factor. You can override by providing a lookaround, which will tell Duat how many Tags to look behind. If you set it to Some(0), lookaround will be disabled.

§Note

Duat works fine with Tags in the middle of a codepoint, but external utilizers may not, so keep that in mind.

Source

pub fn tags_rev( &self, b: usize, lookaround: Option<usize>, ) -> Peekable<Chain<RevBoundsAfter<'_>, RevTagsMapper<'_>>>

An reverse iterator over the Tags of the Text

This iterator will consider some Tags ahead of b, since their ranges may overlap with b.

The amount of tags to look for ahead depeds on the internal min_len factor. You can override by providing a lookaround, which will tell Duat how many Tags to look ahead. If you set it to Some(0), lookaround will be disabled.

§Note

Duat works fine with Tags in the middle of a codepoint, but external utilizers may not, so keep that in mind.

Source

pub fn raw_tags_fwd(&self, b: usize) -> impl Iterator<Item = (usize, RawTag)>

A forward Iterator over the RawTags

This Iterator does not take into account Tag ranges that intersect with the starting point, unlike Text::tags_fwd

Source

pub fn raw_tags_rev(&self, b: usize) -> impl Iterator<Item = (usize, RawTag)>

A reverse Iterator over the RawTags

This Iterator does not take into account Tag ranges that intersect with the starting point, unlike Text::tags_rev

Source

pub fn selections(&self) -> &Selections

The Selections printed to this Text, if they exist

Source

pub fn get_main_sel(&self) -> Option<&Selection>

Gets the main Selection, if there is one

If you want a method that doesn’t return an Option (for convenience), see Text::main_sel.

Source

pub fn main_sel(&self) -> &Selection

Gets the main Selection

§Panics

This method will panic if there are no Selections. If you want a non-panicking method, see Text::get_main_sel.

Source

pub fn get_spawned_ids(&self) -> impl Iterator<Item = SpawnId>

A list of all SpawnIds that belong to this Text

Source

pub fn text_state(&self) -> TextState

A struct representing how many changes took place since the creation of this Text

This struct tracks all Changes and Tag additions/removals, giving you information about wether this Text has changed, when comparing this to previous TextStates of the same Text.

Methods from Deref<Target = Bytes>§

Source

pub fn len(&self) -> Point

The Point at the end of the text

Source

pub fn is_empty(&self) -> bool

Whether or not there are any characters in Bytes, besides the final b'\n'

§Note

This does not check for tags, so with a Tag::Ghost, there could actually be a “string” of characters on the Text, it just wouldn’t be considered real “text”. If you want to check for the InnerTags’b possible emptyness as well, see Text::is_empty_empty.

Source

pub fn char_at(&self, p: impl TextIndex) -> Option<char>

The char at the Point’b position

Source

pub fn strs(&self, range: impl TextRange) -> Option<Strs<'_>>

A subslice of the Bytes

Note that this TextRange is relative to the whole Bytes struct, not just this Strs. This method also clips the ranges so they fit into the range of these Strs.

It will return None if the range does not start or end in valid utf8 boundaries.

§Note

The reason why this function returns two strings is that the contents of the text are stored in a GapBuffer, which works with two strings.

If you want to iterate over them, you can do the following:

let bytes = text.bytes();

for char in bytes.strs(p0..p1).unwrap().chars() {
    todo!();
}

Do note that you should avoid iterators like str::lines, as they will separate the line that is partially owned by each &str:

let broken_up_line = [
    "This is line 1, business as usual.\nThis is line 2, but it",
    "is broken into two separate strings.\nSo 4 lines would be counted, instead of 3",
];

This is one way that the inner GapBuffer could be set up, where one of the lines is split among the two slices.

If you wish to iterate over the lines, see Bytes::lines.

Source

pub fn slices(&self, range: impl TextRange) -> Slices<'_>

An Iterator over the bytes in a given byte range

Unlike strs, this function works with byte ranges, not TextRanges. That’b because Strs is supposed to return valid UTF-8 strings, which need to have valid character terminations, so they should be indexed by a character range, not a byte range.

Since buffers is based on [u8]s, not strs, it doesn’t have the same restrictions, so a byte range can be used instead.

If the range is fully or partially out of bounds, one or both of the slices might be empty.

Source

pub fn lines(&self, range: impl TextRange) -> Lines<'_>

Returns an iterator over the lines in a given range

The lines are inclusive, that is, it will iterate over the whole line, not just the parts within the range.

Source

pub fn point_at_byte(&self, b: usize) -> Point

The Point corresponding to the byte position, 0 indexed

If the byte position would fall in between two characters (because the first one comprises more than one byte), the first character is chosen as the Point where the byte is located.

§Panics

Will panic if b is greater than the length of the text

Source

pub fn point_at_char(&self, c: usize) -> Point

The Point associated with the cth char

§Panics

Will panic if c is greater than the number of chars in the text.

Source

pub fn point_at_line(&self, l: usize) -> Point

The Point where the lth line starts, 0 indexed

If l == number_of_lines, returns the last point of the text.

§Panics

Will panic if the number l is greater than the number of lines on the text

Source

pub fn line_range(&self, l: usize) -> Range<Point>

The start and end Points for the lth line

If l == number_of_lines, these points will be the same.

The second number includes the \n at the end of the line.

§Panics

Will panic if the number l is greater than the number of lines on the text

Source

pub fn last_point(&self) -> Point

The last Point associated with a char

This will give the Point of the last char of the text. The difference between this method and len is that it will return a Point one position earlier than it. If the text is completely empty, it will return None.

Source

pub fn chars_fwd( &self, range: impl TextRange, ) -> Option<impl Iterator<Item = (usize, char)> + '_>

A forward iterator of the chars of Bytes

Each char will be accompanied by a byte index, which is the position where said character starts, e.g. 0 for the first character.

Source

pub fn chars_rev( &self, range: impl TextRange, ) -> Option<impl Iterator<Item = (usize, char)> + '_>

A reverse iterator of the chars in Bytes

Each char will be accompanied by a byte index, which is the position where said character starts, e.g. 0 for the first character.

Source

pub fn indent(&self, p: Point, opts: PrintOpts) -> usize

Gets the indentation level on the current line

Source

pub fn get_contiguous(&self, range: impl TextRange) -> Option<&str>

Tries to get a contiguous &str from the Bytes

Returns None if the gap of the inner buffer was within the given range OR.

Trait Implementations§

Source§

impl<'t> Debug for TextMut<'t>

Source§

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

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

impl<'t> Deref for TextMut<'t>

Source§

type Target = Text

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl PartialEq<&str> for TextMut<'_>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<String> for TextMut<'_>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Text> for TextMut<'_>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<TextMut<'_>> for &str

Source§

fn eq(&self, other: &TextMut<'_>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<TextMut<'_>> for String

Source§

fn eq(&self, other: &TextMut<'_>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<TextMut<'_>> for Text

Source§

fn eq(&self, other: &TextMut<'_>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<TextMut<'_>> for TextMut<'_>

Source§

fn eq(&self, other: &TextMut<'_>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TextMut<'_>

Auto Trait Implementations§

§

impl<'t> Freeze for TextMut<'t>

§

impl<'t> !RefUnwindSafe for TextMut<'t>

§

impl<'t> Send for TextMut<'t>

§

impl<'t> Sync for TextMut<'t>

§

impl<'t> Unpin for TextMut<'t>

§

impl<'t> !UnwindSafe for TextMut<'t>

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

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.