pub fn replace_range(
edit: &mut TextEdit,
config: &Config,
metrics: &Metrics<'_>,
from: usize,
to: usize,
insert: &str,
max_len: Option<u32>,
record: bool,
) -> boolExpand description
Replaces a flat character range with insert, recording one undo item.
The single mutation every other one is written in terms of. max_len
truncates the insertion — never the field — so inserting a long string
into a nearly-full field puts in as much as fits and leaves the rest of
the text alone.
let mut edit = TextEdit::new("ABCDEF", &config, &metrics, true);
// Replace [1, 4) with "xy", recording one undo item.
assert!(ops::replace_range(&mut edit, &config, &metrics, 1, 4, "xy", None, true));
assert_eq!(edit.text, "AxyEF");
assert_eq!(edit.caret_index(), 3, "the caret lands after the insertion");
// Nothing removed and nothing inserted is not an edit.
assert!(!ops::replace_range(&mut edit, &config, &metrics, 2, 2, "", None, true));
// `max_len` truncates the INSERTION, never the field.
let mut limited = TextEdit::new("AB", &config, &metrics, true);
ops::replace_range(&mut limited, &config, &metrics, 2, 2, "xyz", Some(4), true);
assert_eq!(limited.text, "ABxy");