on master help sign in
split_selection
commit2bfdcede32586af01e1e7cda686a48525e0154bd authorBlaž Hrastnik <blaz@mxxn.io> dateMon 14 Dec 2020, 16:02 (6 years ago) parentf92998a
2 files changed+19−16
helix-term/src/commands.rs+18−15 helix-term/src/keymap.rs+1−1
helix-term/src/commands.rs+18−15
@@ -262,23 +262,26 @@ pub fn split_selection(cx: &mut Context) {
262262 // # update state
263263 // }
264264
265− let prompt = Prompt::new(
266− "split:".to_string(),
267− |input: &str| Vec::new(), // TODO: use Option here?
268− |editor: &mut Editor, input: &str| {
269− match Regex::new(input) {
270− Ok(regex) => {
271− let view = editor.view_mut().unwrap();
272− let text = &view.doc.text().slice(..);
273− let selection = selection::split_on_matches(text, view.doc.selection(), &regex);
274− view.doc.set_selection(selection);
265+ cx.callback = Some(Box::new(|compositor: &mut Compositor| {
266+ let prompt = Prompt::new(
267+ "split:".to_string(),
268+ |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
269+ |editor: &mut Editor, input: &str| {
270+ match Regex::new(input) {
271+ Ok(regex) => {
272+ let view = editor.view_mut().unwrap();
273+ let text = &view.doc.text().slice(..);
274+ let selection =
275+ selection::split_on_matches(text, view.doc.selection(), &regex);
276+ view.doc.set_selection(selection);
277+ }
278+ Err(_) => (), // TODO: mark command line as error
275279 }
276− Err(_) => (), // TODO: mark command line as error
277− }
278− },
279− );
280+ },
281+ );
280282
281− unimplemented!()
283+ compositor.push(Box::new(prompt));
284+ }));
282285}
283286
284287pub fn split_selection_on_newline(cx: &mut Context) {
helix-term/src/keymap.rs+1−1
@@ -156,8 +156,8 @@ pub fn default() -> Keymaps {
156156 vec![key!('o')] => commands::open_below,
157157 vec![key!('d')] => commands::delete_selection,
158158 vec![key!('c')] => commands::change_selection,
159− vec![shift!('S')] => commands::split_selection,
160159 vec![key!('s')] => commands::split_selection_on_newline,
160+ vec![shift!('S')] => commands::split_selection,
161161 vec![key!(';')] => commands::collapse_selection,
162162 // TODO should be alt(;)
163163 vec![key!('%')] => commands::flip_selections,