pub struct SelectionHelper { /* private fields */ }Expand description
Text-selection logic
This struct holds a CursorRange. There is no requirement on the order of these two
positions. Each may be adjusted independently.
Additionally, this struct holds the selection anchor index. This usually equals the selection index, but when using double-click or triple-click selection, the anchor represents the initially-clicked position while the selection index represents the expanded position.
Implementations§
Source§impl SelectionHelper
impl SelectionHelper
Sourcepub fn set_cursor(&mut self, index: usize)
pub fn set_cursor(&mut self, index: usize)
Set the cursor position, clearing the selection
Sourcepub fn set_edit_index(&mut self, index: usize)
pub fn set_edit_index(&mut self, index: usize)
Set the cursor index without adjusting the selection index
Sourcepub fn set_sel_index(&mut self, index: usize)
pub fn set_sel_index(&mut self, index: usize)
Set the selection index without adjusting the edit index
The anchor index is also set to the selection index.
Sourcepub fn set_sel_index_only(&mut self, index: usize)
pub fn set_sel_index_only(&mut self, index: usize)
Set the selection index only
Prefer Self::set_sel_index unless you know you don’t want to set the anchor.
Sourcepub fn set_max_len(&mut self, len: usize)
pub fn set_max_len(&mut self, len: usize)
Apply new limit to the maximum length
Call this method if the string changes under the selection to ensure that the selection does not exceed the length of the new string.
Sourcepub fn set_anchor(&mut self, clear: bool)
pub fn set_anchor(&mut self, clear: bool)
Set the anchor to the edit position
This is used to start a drag-selection. If clear, then the selection
position is also set to the edit position.
Self::expand may be used to expand the selection from this anchor.
Sourcepub fn expand<T: FormattableText>(&mut self, text: &Text<T>, lines: bool)
pub fn expand<T: FormattableText>(&mut self, text: &Text<T>, lines: bool)
Expand the selection from the range between edit and anchor positions
This moves the cursor range. To obtain repeatable
behaviour on drag-selection, set the anchor (Self::set_anchor)
initially, then set the edit position and call this method each time
the cursor moves.
The selection is expanded by words or lines (if lines). Line expansion
requires that text has been prepared (Text::prepare).
Sourcepub fn delete_range(&mut self, range: Range<usize>)
pub fn delete_range(&mut self, range: Range<usize>)
Adjust all indices for a deletion from the source text
Methods from Deref<Target = CursorRange>§
Sourcepub fn edit_index(&self) -> usize
pub fn edit_index(&self) -> usize
Get the edit cursor index
Trait Implementations§
Source§impl Clone for SelectionHelper
impl Clone for SelectionHelper
Source§fn clone(&self) -> SelectionHelper
fn clone(&self) -> SelectionHelper
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SelectionHelper
impl Debug for SelectionHelper
Source§impl Default for SelectionHelper
impl Default for SelectionHelper
Source§fn default() -> SelectionHelper
fn default() -> SelectionHelper
Source§impl Deref for SelectionHelper
impl Deref for SelectionHelper
Source§impl DerefMut for SelectionHelper
impl DerefMut for SelectionHelper
Source§impl<T: Into<CursorRange>> From<T> for SelectionHelper
impl<T: Into<CursorRange>> From<T> for SelectionHelper
Auto Trait Implementations§
impl Freeze for SelectionHelper
impl RefUnwindSafe for SelectionHelper
impl Send for SelectionHelper
impl Sync for SelectionHelper
impl Unpin for SelectionHelper
impl UnwindSafe for SelectionHelper
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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> 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.