Skip to main content

replace_selection

Function replace_selection 

Source
pub fn replace_selection(text: &mut String, cursor: &mut TextCursor, s: &str)
Expand description

Replaces the active selection - or, with none, inserts at the caret - with s, leaving the caret after the inserted text and no selection.

The seam every host mutation goes through, so no stale anchor outlives an edit.

ยงExamples

use ratada::input::{TextCursor, replace_selection};

let mut text = String::from("hello");
let mut cursor = TextCursor { pos: 5, anchor: Some(1) };
replace_selection(&mut text, &mut cursor, "i");
assert_eq!((text.as_str(), cursor.pos), ("hi", 2));