Skip to main content

Selection

Struct Selection 

Source
pub struct Selection {
    pub range: Option<SelectionRange>,
}
Expand description

The application’s single selection slot. None means nothing is selected. The library emits SelectionChanged events that fold into this; widgets read it back to draw highlight bands and route editing operations.

Fields§

§range: Option<SelectionRange>

Implementations§

Source§

impl Selection

Source

pub fn caret(key: impl Into<String>, byte: usize) -> Self

A collapsed caret at (key, byte). Convenience for tests and app-side initialization.

Examples found in repository?
examples/settings_calibration.rs (line 212)
208fn setting_field(label: &'static str, value: &'static str, key: &'static str) -> El {
209    form_item([
210        form_label(label),
211        form_control(
212            text_input(value, &Selection::caret(key, value.len()), key).key(
213                if key == "display-name" {
214                    "metric:form.input"
215                } else {
216                    key
217                },
218            ),
219        ),
220    ])
221    .width(Size::Fill(1.0))
222}
More examples
Hide additional examples
examples/polish_calibration.rs (line 324)
317fn form_probe() -> El {
318    form([
319        form_item([
320            form_label("Valid input"),
321            form_control(
322                text_input(
323                    "Valid input",
324                    &Selection::caret("valid-input", 11),
325                    "valid-input",
326                )
327                .key("metric:form.input"),
328            ),
329            form_description("Default field spacing and helper text."),
330        ]),
331        form_item([
332            form_label("Invalid input"),
333            form_control(
334                text_input(
335                    "Invalid input",
336                    &Selection::caret("invalid-input", 13),
337                    "invalid-input",
338                )
339                .invalid(),
340            ),
341            form_message("This field needs attention."),
342        ]),
343        row([
344            button("Disabled").secondary().disabled(),
345            button("Loading").primary().loading(),
346            spacer(),
347        ]),
348    ])
349    .padding(tokens::SPACE_3)
350    .fill(tokens::MUTED)
351    .stroke(tokens::BORDER)
352    .radius(tokens::RADIUS_MD)
353}
Source

pub fn is_empty(&self) -> bool

True when there is no active selection.

Source

pub fn is_within(&self, key: &str) -> bool

True when the selection lives entirely inside key — both anchor and head reference it. False for cross-element selections and for the empty selection.

Source

pub fn anchored_at(&self, key: &str) -> bool

True when key is the anchor’s key (the originating leaf).

Source

pub fn within(&self, key: &str) -> Option<TextSelection>

View the selection through one leaf’s lens: returns Some(TextSelection) only when the selection lives entirely inside key. Cross-element selections return None here — callers that need a per-leaf slice for a spanned leaf should instead consult the document-order range.

Source

pub fn set_within(&mut self, key: &str, sel: TextSelection)

Replace this selection’s slice for key from a freshly produced TextSelection. Used by editable widgets after folding an event: take the slice via Self::within, let the widget mutate it, and write it back. No-op when the selection isn’t currently within key.

Source

pub fn clear(&mut self)

Clear the selection.

Trait Implementations§

Source§

impl Clone for Selection

Source§

fn clone(&self) -> Selection

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Selection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Selection

Source§

fn default() -> Selection

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

impl Eq for Selection

Source§

impl PartialEq for Selection

Source§

fn eq(&self, other: &Selection) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Selection

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.