pub fn replace_selection(
edit: &mut TextEdit,
config: &Config,
metrics: &Metrics<'_>,
text: &str,
max_len: Option<u32>,
) -> boolExpand description
Replaces the selection with text, leaving the caret after it.
One undo item however long the text, which is the difference from typing the same characters one at a time.
A DoNotScroll field already at its plate’s edge refuses the insertion
half — see is_text_overflow — but the removal half still runs
upstream, because ReplaceSelection clears before it inserts. Deleting a
selection therefore always works, however full the field is.
let mut edit = TextEdit::new("AB", &config, &metrics, true);
edit.set_selection(0, 1);
assert!(ops::replace_selection(&mut edit, &config, &metrics, "XYZ", None));
assert_eq!(edit.text, "XYZB");
// A caret is left after the insertion, not a selection over it.
assert_eq!(edit.selected_text(), "");
assert_eq!(edit.caret_index(), 3);
// One undo item however long the text, unlike typing it out.
ops::undo(&mut edit, &config, &metrics);
assert_eq!(edit.text, "AB");