pub struct TextSelection {
pub anchor: usize,
pub caret: usize,
}Expand description
Caret and optional selection anchor (UTF-8 byte indices).
This value does not know the associated text and therefore permits out-of-range
and non-boundary indices. TextEditState::clamp_to_buffer repairs them by
clamping backward to valid UTF-8 boundaries.
§Examples
use ailloli_ui_text::TextSelection;
let selection = TextSelection { anchor: 8, caret: 3 };
assert_eq!(selection.normalized(), (3, 8));Fields§
§anchor: usizeFixed end of an extended selection, as a UTF-8 byte index.
caret: usizeMoving end and active caret, as a UTF-8 byte index.
Implementations§
Source§impl TextSelection
impl TextSelection
Sourcepub fn collapsed(caret: usize) -> Self
pub fn collapsed(caret: usize) -> Self
Creates a zero-width selection at caret without validating it.
§Examples
use ailloli_ui_text::TextSelection;
let selection = TextSelection::collapsed(5);
assert_eq!(selection, TextSelection { anchor: 5, caret: 5 });
assert!(selection.is_collapsed());Sourcepub fn normalized(self) -> (usize, usize)
pub fn normalized(self) -> (usize, usize)
Returns (min(anchor, caret), max(anchor, caret)).
The pair is numerically ordered but is not clamped to any buffer.
§Examples
use ailloli_ui_text::TextSelection;
assert_eq!(TextSelection { anchor: 9, caret: 2 }.normalized(), (2, 9));Sourcepub fn is_collapsed(self) -> bool
pub fn is_collapsed(self) -> bool
Returns true when anchor and caret have the same byte index.
§Examples
use ailloli_ui_text::TextSelection;
assert!(TextSelection::collapsed(0).is_collapsed());
assert!(!TextSelection { anchor: 0, caret: 1 }.is_collapsed());Trait Implementations§
Source§impl Clone for TextSelection
impl Clone for TextSelection
Source§fn clone(&self) -> TextSelection
fn clone(&self) -> TextSelection
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TextSelection
impl Debug for TextSelection
Source§impl PartialEq for TextSelection
impl PartialEq for TextSelection
impl Copy for TextSelection
impl Eq for TextSelection
impl StructuralPartialEq for TextSelection
Auto Trait Implementations§
impl Freeze for TextSelection
impl RefUnwindSafe for TextSelection
impl Send for TextSelection
impl Sync for TextSelection
impl Unpin for TextSelection
impl UnwindSafe for TextSelection
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.