@@ -380,6 +380,29 @@ pub fn extend_prev_char(cx: &mut Context) {
380380 )
381381}
382382
383+pub fn replace(cx: &mut Context) {
384+ // need to wait for next key
385+ cx.on_next_key(move |cx, event| {
386+ if let KeyEvent {
387+ code: KeyCode::Char(ch),
388+ ..
389+ } = event
390+ {
391+ let text = Tendril::from_char(ch);
392+
393+ let mut doc = cx.doc();
394+
395+ let transaction =
396+ Transaction::change_by_selection(doc.text(), doc.selection(), |range| {
397+ (range.from(), range.to() + 1, Some(text.clone()))
398+ });
399+
400+ doc.apply(&transaction);
401+ doc.append_changes_to_history();
402+ }
403+ })
404+}
405+
383406fn scroll(view: &mut View, offset: usize, direction: Direction) {
384407 use Direction::*;
385408 // we use short lived borrows since view's methods read from doc too