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
impl Selection
Sourcepub fn caret(key: impl Into<String>, byte: usize) -> Self
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?
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
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}Sourcepub fn is_within(&self, key: &str) -> bool
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.
Sourcepub fn anchored_at(&self, key: &str) -> bool
pub fn anchored_at(&self, key: &str) -> bool
True when key is the anchor’s key (the originating leaf).
Sourcepub fn within(&self, key: &str) -> Option<TextSelection>
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.
Sourcepub fn set_within(&mut self, key: &str, sel: TextSelection)
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.
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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.