on master help sign in
Implement replace command (r<key>).
commit42d07b0621f034049ba3872122144ea9e69092eb authorBlaž Hrastnik <blaz@mxxn.io> dateFri 19 Mar 2021, 18:01 (6 years ago) parentbf95ee2
2 files changed+25
helix-term/src/commands.rs+23 helix-term/src/keymap.rs+2
helix-term/src/commands.rs+23
@@ -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
helix-term/src/keymap.rs+2
@@ -141,6 +141,8 @@ pub fn default() -> Keymaps {
141141 shift!('T') => commands::till_prev_char,
142142 shift!('F') => commands::find_prev_char,
143143 // and matching set for select mode (extend)
144+ //
145+ key!('r') => commands::replace,
144146
145147 key!('0') => commands::move_line_start,
146148 key!('$') => commands::move_line_end,