pub struct Selection {
pub anchor: usize,
pub focus: usize,
}Expand description
A text selection defined by two byte offsets into the source string.
When anchor == focus the selection is a collapsed caret.
Fields§
§anchor: usizeByte offset where the selection started (the fixed end).
focus: usizeByte offset of the current cursor / the moving end.
Implementations§
Source§impl Selection
impl Selection
Sourcepub fn extend_to(&mut self, focus: usize)
pub fn extend_to(&mut self, focus: usize)
Extend the selection so that the focus moves to focus.
Sourcepub fn is_collapsed(&self) -> bool
pub fn is_collapsed(&self) -> bool
Returns true when anchor and focus are at the same position.
Sourcepub fn normalized(&self) -> (usize, usize)
pub fn normalized(&self) -> (usize, usize)
Returns (start, end) in ascending byte-offset order.
Sourcepub fn byte_to_grapheme(text: &str, byte_offset: usize) -> usize
pub fn byte_to_grapheme(text: &str, byte_offset: usize) -> usize
Convert a UTF-8 byte offset to a grapheme cluster index.
A “grapheme cluster” here is defined as a sequence of bytes whose
first byte has the form 0b0xxx_xxxx (ASCII) or 0b11xx_xxxx
(leading multibyte byte). This is a simplified model; for full
Unicode grapheme cluster segmentation use the unicode-segmentation
crate (not a dependency here per the Pure Rust / no-extra-crate
policy).
Sourcepub fn grapheme_to_byte(text: &str, grapheme_idx: usize) -> usize
pub fn grapheme_to_byte(text: &str, grapheme_idx: usize) -> usize
Convert a grapheme cluster index to the byte offset of its first byte.
Sourcepub fn highlight_rects(
&self,
glyphs: &[Vec<GlyphPosition>],
line_height: f32,
) -> Vec<(f32, f32, f32, f32)>
pub fn highlight_rects( &self, glyphs: &[Vec<GlyphPosition>], line_height: f32, ) -> Vec<(f32, f32, f32, f32)>
Compute highlight rectangles for the selected region.
Returns Vec<(x, y, w, h)> — one rect per line that is (even
partially) covered by the selection.
Sourcepub fn extend_word_forward(text: &str, byte_offset: usize) -> usize
pub fn extend_word_forward(text: &str, byte_offset: usize) -> usize
Return the byte offset just past the end of the word that starts at
or after byte_offset.
Sourcepub fn extend_word_backward(text: &str, byte_offset: usize) -> usize
pub fn extend_word_backward(text: &str, byte_offset: usize) -> usize
Return the byte offset of the start of the word at or before
byte_offset.
Sourcepub fn extend_line_start(
glyphs: &[Vec<GlyphPosition>],
byte_offset: usize,
) -> usize
pub fn extend_line_start( glyphs: &[Vec<GlyphPosition>], byte_offset: usize, ) -> usize
Return the byte offset of the first glyph on the line that contains
byte_offset.
Sourcepub fn extend_line_end(
glyphs: &[Vec<GlyphPosition>],
byte_offset: usize,
) -> usize
pub fn extend_line_end( glyphs: &[Vec<GlyphPosition>], byte_offset: usize, ) -> usize
Return the byte offset past the last glyph on the line that contains
byte_offset.
Trait Implementations§
impl Eq for Selection
impl StructuralPartialEq for Selection
Auto Trait Implementations§
impl Freeze for Selection
impl RefUnwindSafe for Selection
impl Send for Selection
impl Sync for Selection
impl Unpin for Selection
impl UnsafeUnpin 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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 more