Struct Selection
pub struct Selection { /* private fields */ }Expand description
Defines a range within a text layout.
Implementations§
§impl Selection
impl Selection
pub fn new(anchor: Cursor, focus: Cursor) -> Selection
pub fn new(anchor: Cursor, focus: Cursor) -> Selection
Creates a new selection from the given anchor and focus cursors.
pub fn from_byte_index<B>(
layout: &Layout<B>,
index: usize,
affinity: Affinity,
) -> Selectionwhere
B: Brush,
pub fn from_byte_index<B>(
layout: &Layout<B>,
index: usize,
affinity: Affinity,
) -> Selectionwhere
B: Brush,
Creates a new collapsed selection from the given byte index and affinity.
pub fn from_point<B>(layout: &Layout<B>, x: f32, y: f32) -> Selectionwhere
B: Brush,
pub fn from_point<B>(layout: &Layout<B>, x: f32, y: f32) -> Selectionwhere
B: Brush,
Creates a new collapsed selection from the given point.
pub fn word_from_point<B>(layout: &Layout<B>, x: f32, y: f32) -> Selectionwhere
B: Brush,
pub fn word_from_point<B>(layout: &Layout<B>, x: f32, y: f32) -> Selectionwhere
B: Brush,
Creates a new selection bounding the word at the given coordinates.
pub fn line_from_point<B>(layout: &Layout<B>, x: f32, y: f32) -> Selectionwhere
B: Brush,
pub fn line_from_point<B>(layout: &Layout<B>, x: f32, y: f32) -> Selectionwhere
B: Brush,
Creates a new selection bounding the line at the given coordinates.
pub fn hard_line_from_point<B>(layout: &Layout<B>, x: f32, y: f32) -> Selectionwhere
B: Brush,
pub fn hard_line_from_point<B>(layout: &Layout<B>, x: f32, y: f32) -> Selectionwhere
B: Brush,
Creates a new selection bounding the “logical” line at the given coordinates.
That is, the line as defined by line break characters, rather than due to soft-wrapping.
pub fn is_collapsed(&self) -> bool
pub fn is_collapsed(&self) -> bool
Returns true if the anchor and focus of the selection are the same.
This means that the selection represents a single position rather than a range.
pub fn anchor(&self) -> Cursor
pub fn anchor(&self) -> Cursor
Returns the anchor of the selection.
In a non-collapsed selection, this indicates where the selection was initiated.
pub fn focus(&self) -> Cursor
pub fn focus(&self) -> Cursor
Returns the focus of the selection.
In a non-collapsed selection, this indicates the current position.
pub fn collapse(&self) -> Selection
pub fn collapse(&self) -> Selection
Returns a new collapsed selection at the position of the current focus.
pub fn refresh<B>(&self, layout: &Layout<B>) -> Selectionwhere
B: Brush,
pub fn refresh<B>(&self, layout: &Layout<B>) -> Selectionwhere
B: Brush,
Returns a new selection that is guaranteed to be within the bounds of the given layout.
pub fn text_range(&self) -> Range<usize>
pub fn text_range(&self) -> Range<usize>
Returns the underlying text range of the selection.
pub fn next_visual<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
pub fn next_visual<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
Returns a new selection with the focus at the next cluster in visual order.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn previous_visual<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
pub fn previous_visual<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
Returns a new selection with the focus at the previous cluster in visual order.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn next_visual_word<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
pub fn next_visual_word<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
Returns a new selection with the focus moved to the next word in visual order.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn previous_visual_word<B>(
&self,
layout: &Layout<B>,
extend: bool,
) -> Selectionwhere
B: Brush,
pub fn previous_visual_word<B>(
&self,
layout: &Layout<B>,
extend: bool,
) -> Selectionwhere
B: Brush,
Returns a new selection with the focus moved to the previous word in visual order.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn next_line<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
pub fn next_line<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
Returns a new selection with the focus moved to the next line. The current horizontal position will be maintained.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn previous_line<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
pub fn previous_line<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
Returns a new selection with the focus moved to the previous line. The current horizontal position will be maintained.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn move_lines<B>(
&self,
layout: &Layout<B>,
delta: isize,
extend: bool,
) -> Selectionwhere
B: Brush,
pub fn move_lines<B>(
&self,
layout: &Layout<B>,
delta: isize,
extend: bool,
) -> Selectionwhere
B: Brush,
Returns a new selection with the focus moved the specified number of lines.
The sign of the delta parameter determines the direction to move with
negative values moving toward previous lines and positive ones moving
toward next lines.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn line_start<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
pub fn line_start<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
Returns a new selection with the focus moved to the start of the current line.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn hard_line_start<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
pub fn hard_line_start<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
Returns a new selection with the focus moved to just after the previous hard line break.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn line_end<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
pub fn line_end<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
Returns a new selection with the focus moved to the end of the current line.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn hard_line_end<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
pub fn hard_line_end<B>(&self, layout: &Layout<B>, extend: bool) -> Selectionwhere
B: Brush,
Returns a new selection with the focus moved to just before the next hard line break.
If extend is true then the current anchor will be retained,
otherwise the new selection will be collapsed.
pub fn extend_to_point<B>(
&self,
layout: &Layout<B>,
x: f32,
y: f32,
) -> Selectionwhere
B: Brush,
pub fn extend_to_point<B>(
&self,
layout: &Layout<B>,
x: f32,
y: f32,
) -> Selectionwhere
B: Brush,
Returns a new selection with the focus extended to the given point.
If the initial selection was created from a word or line, then the new selection will be extended at the same granularity.
pub fn shift_click_extension<B>(
&self,
layout: &Layout<B>,
x: f32,
y: f32,
) -> Selectionwhere
B: Brush,
pub fn shift_click_extension<B>(
&self,
layout: &Layout<B>,
x: f32,
y: f32,
) -> Selectionwhere
B: Brush,
Returns a new selection with the focus extended to the given point.
pub fn extend(&self, focus: Cursor) -> Selection
pub fn extend(&self, focus: Cursor) -> Selection
Returns a new selection with the current anchor and the focus set to the given value.
pub fn geometry<B>(&self, layout: &Layout<B>) -> Vec<(BoundingBox, usize)>where
B: Brush,
pub fn geometry<B>(&self, layout: &Layout<B>) -> Vec<(BoundingBox, usize)>where
B: Brush,
Returns a vector containing the rectangles which represent the visual geometry of this selection for the given layout, and the indices of the lines to which they belong.
This is a convenience method built on geometry_with.
pub fn geometry_with<B>(
&self,
layout: &Layout<B>,
f: impl FnMut(BoundingBox, usize),
)where
B: Brush,
pub fn geometry_with<B>(
&self,
layout: &Layout<B>,
f: impl FnMut(BoundingBox, usize),
)where
B: Brush,
Invokes f with the sequence of rectangles which represent the visual
geometry of this selection for the given layout, and the indices of the
lines to which they belong.
This avoids allocation if the intent is to render the rectangles immediately.
Trait Implementations§
impl Copy for Selection
impl Eq 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§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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
impl<T> Brush for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§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
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more§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().