pub struct Text(/* private fields */);Expand description
Implementations§
Source§impl Text
impl Text
Sourcepub fn with_default_main_selection() -> Self
pub fn with_default_main_selection() -> Self
Returns a new empty Text with Selections enabled
Sourcepub fn is_empty_empty(&self) -> bool
pub fn is_empty_empty(&self) -> bool
Sourcepub fn bytes(&self) -> &Bytes
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.
Sourcepub fn indent(&self, p: Point, area: &Area, opts: PrintOpts) -> usize
pub fn indent(&self, p: Point, area: &Area, opts: PrintOpts) -> usize
Gets the indentation level on the current line
Sourcepub fn ghost_max_points_at(&self, b: usize) -> TwoPoints
pub fn ghost_max_points_at(&self, b: usize) -> TwoPoints
Sourcepub fn len_points(&self) -> TwoPoints
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.
Sourcepub fn points_after(&self, tp: TwoPoints) -> Option<TwoPoints>
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.
Sourcepub fn visual_line_start(&self, points: TwoPoints, skip: usize) -> TwoPoints
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.
Sourcepub fn replace_range(&mut self, range: impl TextRange, edit: impl ToString)
pub fn replace_range(&mut self, range: impl TextRange, edit: impl ToString)
Sourcepub fn insert_text(&mut self, p: impl TextIndex, text: &Text)
pub fn insert_text(&mut self, p: impl TextIndex, text: &Text)
Sourcepub fn new_moment(&mut self)
pub fn new_moment(&mut self)
Finishes the current moment and adds a new one to the history
Sourcepub fn save_on(&mut self, writer: impl Write) -> Result<usize>
pub fn save_on(&mut self, writer: impl Write) -> Result<usize>
Writes the contents of this Text to a writer
Sourcepub fn has_unsaved_changes(&self) -> bool
pub fn has_unsaved_changes(&self) -> bool
Sourcepub fn insert_tag<I, R>(
&mut self,
tagger: Tagger,
r: I,
tag: impl Tag<I, R>,
) -> Option<R>where
R: Copy,
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
Sourcepub fn insert_tag_after<I, R>(
&mut self,
tagger: Tagger,
r: I,
tag: impl Tag<I, R>,
) -> Option<R>where
R: Copy,
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
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.
Sourcepub fn no_selections(self) -> Selectionless
pub fn no_selections(self) -> Selectionless
Returns a Text without Selections
You should use this if you want to send the Text across
threads.
Sourcepub fn iter_fwd(&self, at: TwoPoints) -> FwdIter<'_> ⓘ
pub fn iter_fwd(&self, at: TwoPoints) -> FwdIter<'_> ⓘ
A forward iterator of the chars and tags of the Text
Sourcepub fn iter_rev(&self, at: TwoPoints) -> RevIter<'_> ⓘ
pub fn iter_rev(&self, at: TwoPoints) -> RevIter<'_> ⓘ
A reverse iterator of the chars and tags of the Text
Sourcepub fn chars_fwd(
&self,
range: impl TextRange,
) -> Option<impl Iterator<Item = (Point, char)> + '_>
pub fn chars_fwd( &self, range: impl TextRange, ) -> Option<impl Iterator<Item = (Point, char)> + '_>
A forward iterator of the chars of the Text
Each char will be accompanied by a Point, which is the
position where said character starts, e.g.
Point::default() for the first character
Sourcepub fn chars_rev(
&self,
range: impl TextRange,
) -> Option<impl Iterator<Item = (Point, char)> + '_>
pub fn chars_rev( &self, range: impl TextRange, ) -> Option<impl Iterator<Item = (Point, char)> + '_>
A reverse iterator of the chars of the Text
Each char will be accompanied by a Point, which is the
position where said character starts, e.g.
Point::default() for the first character
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
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
Sourcepub fn selections(&self) -> &Selections
pub fn selections(&self) -> &Selections
The Selections printed to this Text, if they exist
Sourcepub fn selections_mut(&mut self) -> &mut Selections
pub fn selections_mut(&mut self) -> &mut Selections
A mut reference to this Text’s Selections if they
exist
Sourcepub fn get_spawned_ids(&self) -> impl Iterator<Item = SpawnId>
pub fn get_spawned_ids(&self) -> impl Iterator<Item = SpawnId>
A list of all SpawnIds that belong to this Text
Methods from Deref<Target = Bytes>§
Sourcepub fn is_empty(&self) -> bool
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’s possible emptyness as
well, see Text::is_empty_empty.
Sourcepub fn slices(&self, range: impl TextRange) -> Slices<'_> ⓘ
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’s 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.
Sourcepub fn strs(&self, range: impl TextRange) -> Option<Strs<'_>>
pub fn strs(&self, range: impl TextRange) -> Option<Strs<'_>>
An Iterator over the &strs of the Text
§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.
Sourcepub fn lines(&self, range: impl TextRange) -> Lines<'_>
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.
Sourcepub fn point_at_byte(&self, b: usize) -> Point
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
Sourcepub fn point_at_char(&self, c: usize) -> Point
pub fn point_at_char(&self, c: usize) -> Point
Sourcepub fn point_at_line(&self, l: usize) -> Point
pub fn point_at_line(&self, l: usize) -> Point
Sourcepub fn line_range(&self, l: usize) -> Range<Point>
pub fn line_range(&self, l: usize) -> Range<Point>
Sourcepub fn last_point(&self) -> Point
pub fn last_point(&self) -> Point
Sourcepub fn chars_fwd(
&self,
range: impl TextRange,
) -> Option<impl Iterator<Item = (Point, char)> + '_>
pub fn chars_fwd( &self, range: impl TextRange, ) -> Option<impl Iterator<Item = (Point, char)> + '_>
A forward iterator of the chars of Bytes
Each char will be accompanied by a Point, which is the
position where said character starts, e.g.
Point::default() for the first character
Sourcepub fn chars_rev(
&self,
range: impl TextRange,
) -> Option<impl Iterator<Item = (Point, char)> + '_>
pub fn chars_rev( &self, range: impl TextRange, ) -> Option<impl Iterator<Item = (Point, char)> + '_>
A reverse iterator of the chars in Bytes
Each char will be accompanied by a Point, which is the
position where said character starts, e.g.
Point::default() for the first character
Sourcepub fn indent(&self, p: Point, opts: PrintOpts) -> usize
pub fn indent(&self, p: Point, opts: PrintOpts) -> usize
Gets the indentation level on the current line
Sourcepub fn get_contiguous(&self, range: impl TextRange) -> Option<&str>
pub fn get_contiguous(&self, range: impl TextRange) -> Option<&str>
Sourcepub fn search_fwd<R: RegexPattern>(
&self,
pat: R,
range: impl TextRange,
) -> Result<impl Iterator<Item = R::Match> + '_, Box<Error>>
pub fn search_fwd<R: RegexPattern>( &self, pat: R, range: impl TextRange, ) -> Result<impl Iterator<Item = R::Match> + '_, Box<Error>>
Searches forward for a RegexPattern in a range
A RegexPattern can either be a single regex string, an
array of strings, or a slice of strings. When there are more
than one pattern, The return value will include which pattern
matched.
The patterns will also automatically be cached, so you don’t need to do that.
Sourcepub fn search_rev<R: RegexPattern>(
&self,
pat: R,
range: impl TextRange,
) -> Result<impl Iterator<Item = R::Match> + '_, Box<Error>>
pub fn search_rev<R: RegexPattern>( &self, pat: R, range: impl TextRange, ) -> Result<impl Iterator<Item = R::Match> + '_, Box<Error>>
Searches in reverse for a RegexPattern in a range
A RegexPattern can either be a single regex string, an
array of strings, or a slice of strings. When there are more
than one pattern, The return value will include which pattern
matched.
The patterns will also automatically be cached, so you don’t need to do that.
Trait Implementations§
Source§impl AsBuilderPart for Text
impl AsBuilderPart for Text
Source§fn as_builder_part(&self) -> BuilderPart<'_>
fn as_builder_part(&self) -> BuilderPart<'_>
BuilderPart fro this valueSource§impl From<Selectionless> for Text
impl From<Selectionless> for Text
Source§fn from(value: Selectionless) -> Self
fn from(value: Selectionless) -> Self
Auto Trait Implementations§
impl Freeze for Text
impl !RefUnwindSafe for Text
impl Send for Text
impl !Sync for Text
impl Unpin for Text
impl !UnwindSafe for Text
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.