pub struct Text(/* private fields */);Expand description
Implementations§
Source§impl Text
impl Text
Sourcepub fn search_fwd<R: RegexPattern>(
&mut self,
pat: R,
range: impl TextRange,
) -> Result<impl Iterator<Item = R::Match> + '_, Box<Error>>
pub fn search_fwd<R: RegexPattern>( &mut 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>(
&mut self,
pat: R,
range: impl TextRange,
) -> Result<impl Iterator<Item = R::Match> + '_, Box<Error>>
pub fn search_rev<R: RegexPattern>( &mut 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.
Source§impl Text
impl Text
Sourcepub fn new_with_selections() -> Self
pub fn new_with_selections() -> Self
Returns a new empty Text with Selections enabled
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether or not there are any characters in the Text
This ignores the last '\n' in the Text, since it is
always there no matter what.
This does not check for tags, so with a Ghost,
there could actually be a “string” of characters on the
Text, it just wouldn’t be considered real “text”. If you
want to make sure it is indeed empty, see
is_empty_empty.
Sourcepub fn is_empty_empty(&self) -> bool
pub fn is_empty_empty(&self) -> bool
Sourcepub fn strs(&self, range: impl TextRange) -> Strs<'_> ⓘ
pub fn strs(&self, range: impl TextRange) -> 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 text = Text::new();
text.strs(p1..p2).flat_map(str::chars);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",
];§TextRange behavior:
If you give a single usize/Point, it will be
interpreted as a range from.
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 bytes_mut(&mut self) -> &mut Bytes
pub fn bytes_mut(&mut self) -> &mut Bytes
The inner bytes of the Text, mutably
Do note that this mutability isn’t actually for modifying the
Bytes themselves, but instead it is used by some methods
to read said bytes, like make_contiguous or lines
The &mut Bytes and MutTags
Sourcepub fn indent(&self, p: Point, area: &impl RawArea, cfg: PrintCfg) -> usize
pub fn indent(&self, p: Point, area: &impl RawArea, cfg: PrintCfg) -> usize
Gets the indentation level on the current line
Sourcepub fn point_at(&self, b: usize) -> Point
pub fn point_at(&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 points_of_line(&self, l: usize) -> [Point; 2]
pub fn points_of_line(&self, l: usize) -> [Point; 2]
Sourcepub fn len_points(&self) -> (Point, Option<Point>)
pub fn len_points(&self) -> (Point, Option<Point>)
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 last_point(&self) -> Option<Point>
pub fn last_point(&self) -> Option<Point>
Sourcepub fn points_after(&self, tp: impl TwoPoints) -> Option<(Point, Option<Point>)>
pub fn points_after(&self, tp: impl TwoPoints) -> Option<(Point, Option<Point>)>
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 replace_range(&mut self, range: impl TextRange, edit: impl ToString)
pub fn replace_range(&mut self, range: impl TextRange, edit: impl ToString)
Sourcepub fn update_bounds(&mut self)
pub fn update_bounds(&mut self)
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 last_unprocessed_moment(&mut self) -> Option<Vec<Moment>>
pub fn last_unprocessed_moment(&mut self) -> Option<Vec<Moment>>
Sourcepub fn has_unsaved_changes(&self) -> bool
pub fn has_unsaved_changes(&self) -> bool
Sourcepub fn insert_tag<R>(&mut self, tagger: Tagger, r: R, tag: impl Tag<R>)
pub fn insert_tag<R>(&mut self, tagger: Tagger, r: R, tag: impl Tag<R>)
Inserts a Tag at the given position
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 Files Text, as
it must iterate over all tags in the file, 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 enable_selections(&mut self)
pub fn enable_selections(&mut self)
Enables the usage of Selections in this Text
This is automatically done whenever you use the cursor editing
functions of a Handle.
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: impl TwoPoints) -> FwdIter<'_> ⓘ
pub fn iter_fwd(&self, at: impl TwoPoints) -> FwdIter<'_> ⓘ
A forward iterator of the chars and tags of the Text
Sourcepub fn iter_rev(&self, at: impl TwoPoints) -> RevIter<'_> ⓘ
pub fn iter_rev(&self, at: impl TwoPoints) -> RevIter<'_> ⓘ
A reverse iterator of the chars and tags of the Text
Sourcepub fn chars_fwd(&self, p: Point) -> impl Iterator<Item = (Point, char)> + '_
pub fn chars_fwd(&self, p: Point) -> 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, p: Point) -> impl Iterator<Item = (Point, char)> + '_
pub fn chars_rev(&self, p: Point) -> 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) -> Option<&Selections>
pub fn selections(&self) -> Option<&Selections>
The Selections printed to this Text, if they exist
Sourcepub fn selections_mut(&mut self) -> Option<&mut Selections>
pub fn selections_mut(&mut self) -> Option<&mut Selections>
A mut reference to this Text’s Selections if they
exist
Sourcepub fn contiguous(&mut self, range: impl TextRange) -> &str
pub fn contiguous(&mut self, range: impl TextRange) -> &str
Gets a single &str from a given range
This is the equivalent of calling
Bytes::make_contiguous and Bytes::get_contiguous.
While this takes less space in code, calling the other two
functions means that you won’t be mutably borrowing the
Bytes anymore, so if that matters to you, you should do
that.
Sourcepub fn make_contiguous(&mut self, range: impl TextRange)
pub fn make_contiguous(&mut self, range: impl TextRange)
Moves the GapBuffer’s gap, so that the range is whole
The return value is the value of the gap, if the second &str
is the contiguous one.
Sourcepub fn get_contiguous(&self, range: impl TextRange) -> Option<&str>
pub fn get_contiguous(&self, range: impl TextRange) -> Option<&str>
Assumes that the range given is contiguous in self
You MUST call make_contiguous before using this
function. The sole purpose of this function is to not keep the
Bytes mutably borrowed.