diff options
author | Blaž Hrastnik | 2020-12-14 07:02:07 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-12-14 07:02:07 +0000 |
commit | 2bfdcede32586af01e1e7cda686a48525e0154bd (patch) | |
tree | 669b436ff788e499ebdea604dd62f32c3f3d53a1 | |
parent | f92998a14b3017371c6a55756c60c03e126ae23f (diff) |
split_selection
-rw-r--r-- | helix-term/src/commands.rs | 33 | ||||
-rw-r--r-- | helix-term/src/keymap.rs | 2 |
2 files changed, 19 insertions, 16 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7001aa11..3db112d3 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -262,23 +262,26 @@ pub fn split_selection(cx: &mut Context) { // # update state // } - let prompt = Prompt::new( - "split:".to_string(), - |input: &str| Vec::new(), // TODO: use Option here? - |editor: &mut Editor, input: &str| { - match Regex::new(input) { - Ok(regex) => { - let view = editor.view_mut().unwrap(); - let text = &view.doc.text().slice(..); - let selection = selection::split_on_matches(text, view.doc.selection(), ®ex); - view.doc.set_selection(selection); + cx.callback = Some(Box::new(|compositor: &mut Compositor| { + let prompt = Prompt::new( + "split:".to_string(), + |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate + |editor: &mut Editor, input: &str| { + match Regex::new(input) { + Ok(regex) => { + let view = editor.view_mut().unwrap(); + let text = &view.doc.text().slice(..); + let selection = + selection::split_on_matches(text, view.doc.selection(), ®ex); + view.doc.set_selection(selection); + } + Err(_) => (), // TODO: mark command line as error } - Err(_) => (), // TODO: mark command line as error - } - }, - ); + }, + ); - unimplemented!() + compositor.push(Box::new(prompt)); + })); } pub fn split_selection_on_newline(cx: &mut Context) { diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 304a173c..884c04a1 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -156,8 +156,8 @@ pub fn default() -> Keymaps { vec![key!('o')] => commands::open_below, vec![key!('d')] => commands::delete_selection, vec![key!('c')] => commands::change_selection, - vec![shift!('S')] => commands::split_selection, vec![key!('s')] => commands::split_selection_on_newline, + vec![shift!('S')] => commands::split_selection, vec![key!(';')] => commands::collapse_selection, // TODO should be alt(;) vec![key!('%')] => commands::flip_selections, |