pub struct SelectionHelper { /* private fields */ }
Expand description
Text-selection logic
This struct holds an “edit pos” and a “selection pos”, which together form a range. There is no requirement on the order of these two positions. Each may be adjusted independently.
Implementations§
Source§impl SelectionHelper
impl SelectionHelper
Sourcepub fn new(edit_pos: usize, sel_pos: usize) -> Self
pub fn new(edit_pos: usize, sel_pos: usize) -> Self
Construct from (edit, selection)
positions
The anchor position is set to the selection position.
Sourcepub fn set_edit_pos(&mut self, pos: usize)
pub fn set_edit_pos(&mut self, pos: usize)
Set the edit pos without adjusting the selection pos
Sourcepub fn set_sel_pos(&mut self, pos: usize)
pub fn set_sel_pos(&mut self, pos: usize)
Set the selection pos without adjusting the edit pos
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 range(&self) -> Range<usize>
pub fn range(&self) -> Range<usize>
Construct a range from the edit pos and selection pos
The range is from the minimum of (edit pos, selection pos) to the maximum of the two.
Sourcepub fn set_anchor(&mut self)
pub fn set_anchor(&mut self)
Set the anchor position from the edit position
Sourcepub fn expand<T: FormattableText>(&mut self, text: &Text<T>, repeats: u32)
pub fn expand<T: FormattableText>(&mut self, text: &Text<T>, repeats: u32)
Expand the selection from the range between edit pos and anchor pos
This moves both edit pos and sel pos. To obtain repeatable behaviour,
first use SelectionHelper::set_anchor
to set the anchor position,
then before each time this method is called set the edit position.
If repeats <= 2
, the selection is expanded by words, otherwise it is
expanded by lines. Line expansion only works if text is line-wrapped
(layout has been solved).
Sourcepub fn action<T: FormattableText>(
&mut self,
text: &Text<T>,
action: SelectionAction,
)
pub fn action<T: FormattableText>( &mut self, text: &Text<T>, action: SelectionAction, )
Handle an action
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
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.