pub struct Text { /* private fields */ }Expand description
The text in a given Area
Implementations§
Source§impl Text
impl Text
Source§impl Text
impl Text
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Wether or not there are any characters in the Text
§Note
This does not check for tags, so with a Tag::GhostText,
there could actually be a “string” of characters on the
Text, it just wouldn’t be considered real “text”.
Sourcepub fn strs(&self) -> [&str; 2]
pub fn strs(&self) -> [&str; 2]
The two &strs that compose the buffer
In order to iterate over them, I recommend using the
flat_map method:
let text = Text::new();
text.strs().into_iter().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 This is line 2, but it",
"is broken into two separate strings So 4 lines would be counted, \
instead of 3",
];If you want the two &strs in a range, see
strs_in_range
Sourcepub fn strs_in_range(&self, (p1, p2): (Point, Point)) -> [&str; 2]
pub fn strs_in_range(&self, (p1, p2): (Point, Point)) -> [&str; 2]
This method will return two &strs at the Point range
This function treats any Points outside the range as if
they where the last point in 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_in_range((p1, p2))
.into_iter()
.flat_map(str::bytes);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",
];Sourcepub fn point_at(&self, at: u32) -> Point
pub fn point_at(&self, at: u32) -> 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 at is greater than the lenght of the text
Sourcepub fn point_at_char(&self, at: u32) -> Point
pub fn point_at_char(&self, at: u32) -> Point
Sourcepub fn point_at_line(&self, at: u32) -> Point
pub fn point_at_line(&self, at: u32) -> Point
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
Tag::GhostText at the end of the text.
Sourcepub fn last_point(&self) -> Option<Point>
pub fn last_point(&self) -> Option<Point>
Sourcepub fn ghost_max_points_at(&self, at: u32) -> (Point, Option<Point>)
pub fn ghost_max_points_at(&self, at: u32) -> (Point, Option<Point>)
The maximum points in the atth byte
This point is essentially the point at that byte, plus the
last possible Point of any Tag::GhostTexts in that
position.
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 iterater reversibly right after a certain point, thus including the character of said point.
pub fn replace_range(&mut self, range: (Point, Point), edit: impl ToString)
Sourcepub fn undo(&mut self, area: &impl Area, cursors: &mut Cursors, cfg: PrintCfg)
pub fn undo(&mut self, area: &impl Area, cursors: &mut Cursors, cfg: PrintCfg)
Undoes the last moment, if there was one
Sourcepub fn redo(&mut self, area: &impl Area, cursors: &mut Cursors, cfg: PrintCfg)
pub fn redo(&mut self, area: &impl Area, cursors: &mut Cursors, cfg: PrintCfg)
Redoes the last moment in the history, if there is one
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 iter_fwd(&self, at: impl TwoPoints) -> Iter<'_> ⓘ
pub fn iter_fwd(&self, at: impl TwoPoints) -> Iter<'_> ⓘ
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
Trait Implementations§
impl Eq for Text
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)