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,
) -> i32
pub fn move_ver( &mut self, by: i32, text: &Text, area: &Area, opts: PrintOpts, ) -> i32
Internal vertical movement function.
Returns the distance moved in lines.
Sourcepub fn move_ver_wrapped(
&mut self,
by: i32,
text: &Text,
area: &Area,
opts: PrintOpts,
) -> i32
pub fn move_ver_wrapped( &mut self, by: i32, text: &Text, area: &Area, opts: PrintOpts, ) -> i32
Internal vertical movement function.
Returns the distance moved in wrapped lines.
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, bytes: &Bytes) -> Range<usize>
pub fn byte_range(&self, bytes: &Bytes) -> 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, bytes: &Bytes) -> Range<Point>
pub fn point_range(&self, bytes: &Bytes) -> 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
Trait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for Selection
impl<'__de, __Context> BorrowDecode<'__de, __Context> for Selection
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Auto Trait Implementations§
impl !Freeze for Selection
impl RefUnwindSafe for Selection
impl Send for Selection
impl Sync for Selection
impl Unpin for Selection
impl UnwindSafe for Selection
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.