Struct druid_shell::text::Selection [−][src]
#[non_exhaustive]pub struct Selection {
pub anchor: usize,
pub active: usize,
pub h_pos: Option<f64>,
}
Expand description
A range of selected text, or a caret.
A caret is the blinking vertical bar where text is to be inserted. We
represent it as a selection with zero length, where anchor == active
.
Indices are always expressed in UTF-8 bytes, and must be between 0 and the
document length, inclusive.
As an example, if the input caret is at the start of the document hello world
, we would expect both anchor
and active
to be 0
. If the user
holds shift and presses the right arrow key five times, we would expect the
word hello
to be selected, the anchor
to still be 0
, and the active
to now be 5
.
Fields (Non-exhaustive)
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.anchor: usize
The ‘anchor’ end of the selection.
This is the end of the selection that stays unchanged while holding shift and pressing the arrow keys.
active: usize
The ‘active’ end of the selection.
This is the end of the selection that moves while holding shift and pressing the arrow keys.
h_pos: Option<f64>
The saved horizontal position, during vertical movement.
This should not be set by the IME; it will be tracked and handled by the text field.
Implementations
Create a new Selection
with the provided anchor
and active
positions.
Both positions refer to UTF-8 byte indices in some text.
If your selection is a caret, you can use Selection::caret
instead.
Create a new caret (zero-length selection) at the provided UTF-8 byte index.
index
must be a grapheme cluster boundary.
Construct a new selection from this selection, with the provided h_pos.
Note
h_pos
is used to track the pixel location of the cursor when moving
vertically; lines may have available cursor positions at different
positions, and arrowing down and then back up should always result
in a cursor at the original starting location; doing this correctly
requires tracking this state.
You probably don’t need to use this, unless you are implementing a new text field, or otherwise implementing vertical cursor motion, in which case you will want to set this during vertical motion if it is not already set.
Create a new selection that is guaranteed to be valid for the provided text.
Return the position of the upstream end of the selection.
This is end with the lesser byte index.
Because of bidirectional text, this is not necessarily “left”.
Return the position of the downstream end of the selection.
This is the end with the greater byte index.
Because of bidirectional text, this is not necessarily “right”.
The sequential range of the document represented by this selection.
This is the range that would be replaced if text were inserted at this selection.
The length, in bytes of the selected region.
If the selection is a caret, this is 0
.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Selection
impl UnwindSafe for Selection
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn round_from(x: T) -> T
pub fn round_from(x: T) -> T
Performs the conversion.
pub fn round_into(self) -> U
pub fn round_into(self) -> U
Performs the conversion.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more