pub struct Selection { /* private fields */ }Expand description
A cursor in the text buffer. This is an editing cursor, -(not a printing cursor.
Implementations§
Source§impl Selection
impl Selection
Sourcepub fn move_to(&mut self, idx: impl TextIndex, text: &Text)
pub fn move_to(&mut self, idx: impl TextIndex, text: &Text)
Moves to specific, pre calculated Point.
Sourcepub fn move_hor(&mut self, by: i32, text: &Text) -> i32
pub fn move_hor(&mut self, by: i32, text: &Text) -> i32
Internal horizontal movement function
Returns true if the caret was moved
Sourcepub fn move_ver(
&mut self,
by: i32,
text: &Text,
area: &Area,
opts: PrintOpts,
) -> bool
pub fn move_ver( &mut self, by: i32, text: &Text, area: &Area, opts: PrintOpts, ) -> bool
Internal vertical movement function.
Returns true if the caret actually moved at all.
Sourcepub fn move_ver_wrapped(
&mut self,
by: i32,
text: &Text,
area: &Area,
opts: PrintOpts,
) -> bool
pub fn move_ver_wrapped( &mut self, by: i32, text: &Text, area: &Area, opts: PrintOpts, ) -> bool
Internal vertical movement function.
Returns true if the caret actually moved at all.
Sourcepub fn set_anchor(&mut self)
pub fn set_anchor(&mut self)
Sets the position of the anchor to be the same as the current cursor position in the buffer
The anchor and current act as a range of text on the
buffer.
Sourcepub fn unset_anchor(&mut self) -> Option<Point>
pub fn unset_anchor(&mut self) -> Option<Point>
Unsets the anchor, returning its byte index if it existed
This is done so the cursor no longer has a valid selection.
Sourcepub fn anchor(&self) -> Option<Point>
pub fn anchor(&self) -> Option<Point>
Returns the byte index of this Selection’s anchor, if
there is one
Sourcepub fn byte_range(&self, text: &Text) -> Range<usize>
pub fn byte_range(&self, text: &Text) -> Range<usize>
Returns the byte index range between the caret and
anchor
If anchor isn’t set, returns an empty range on caret.
§Note
This range is inclusive, that is, it will include the
character at the end. If you use it to replace a range in
the Text, know that this range will be truncated to
not include the last \n, since it is not allowed to be
removed.
Sourcepub fn start_point(&self) -> Point
pub fn start_point(&self) -> Point
Sourcepub fn point_range(&self, text: &Text) -> Range<Point>
pub fn point_range(&self, text: &Text) -> Range<Point>
Returns the range between caret and anchor.
If anchor isn’t set, returns a range that contains only
the caret’s current char.
Sourcepub fn point_range_excl(&self) -> Range<Point>
pub fn point_range_excl(&self) -> Range<Point>
Returns an exclusive range between caret and anchor
If anchor isn’t set, both Points will be the same.
Sourcepub fn set_desired_cols(&mut self, v: usize, w: usize)
pub fn set_desired_cols(&mut self, v: usize, w: usize)
Sets both the desired visual column, as well as the desired wrapped column