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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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.

Returns true if the selection’s length is 0.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

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