Skip to main content

replace_selection

Function replace_selection 

Source
pub fn replace_selection<R: Resolve>(
    session: &mut FormSession,
    ctx: &Context<'_, R>,
    field: FieldId,
    text: &str,
) -> bool
Expand description

Replaces a field’s selection with text, or deletes it when text is empty.

The embedder’s paste, and half of its cut. Answers whether the field changed — which an empty replacement of an empty selection does not, and a read-only field never does.

§Examples

// The embedder's paste, at the caret the click left.
assert!(route::replace_selection(&mut session, &ctx, FieldId(0), "Hello"));

let Some(FieldState::Text(state)) = session.fields.get(&FieldId(0)) else {
    unreachable!("the click built the field's state")
};
assert_eq!(state.edit.text, "oldHello");

// A field the session has never built state for has no selection to
// replace, and refuses rather than creating one.
assert!(!route::replace_selection(&mut session, &ctx, FieldId(9), "x"));