on master help sign in
split_selection
2bfdcedBlaž Hrastnik
helix-term/src/commands.rs+18−15
@@ -262,23 +262,26 @@ pub fn split_selection(cx: &mut Context) {
262 // # update state
262 // # update state
263 // }
263 // }
264
264
265+ cx.callback = Some(Box::new(|compositor: &mut Compositor| {
265− let prompt = Prompt::new(
266+ let prompt = Prompt::new(
266− "split:".to_string(),
267+ "split:".to_string(),
267− |input: &str| Vec::new(), // TODO: use Option here?
268+ |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
268− |editor: &mut Editor, input: &str| {
269+ |editor: &mut Editor, input: &str| {
269− match Regex::new(input) {
270+ match Regex::new(input) {
270− Ok(regex) => {
271+ Ok(regex) => {
271− let view = editor.view_mut().unwrap();
272+ let view = editor.view_mut().unwrap();
272− let text = &view.doc.text().slice(..);
273+ let text = &view.doc.text().slice(..);
274+ let selection =
273− let selection = selection::split_on_matches(text, view.doc.selection(), &regex);
275+ selection::split_on_matches(text, view.doc.selection(), &regex);
274− view.doc.set_selection(selection);
276+ view.doc.set_selection(selection);
277+ }
278+ Err(_) => (), // TODO: mark command line as error
275 }
279 }
276− Err(_) => (), // TODO: mark command line as error
277− }
280+ },
278− },
279− );
281+ );
280
282
281− unimplemented!()
283+ compositor.push(Box::new(prompt));
284+ }));
282}
285}
283
286
284pub fn split_selection_on_newline(cx: &mut Context) {
287pub fn split_selection_on_newline(cx: &mut Context) {
helix-term/src/keymap.rs+1−1
@@ -156,8 +156,8 @@ pub fn default() -> Keymaps {
156 vec![key!('o')] => commands::open_below,
156 vec![key!('o')] => commands::open_below,
157 vec![key!('d')] => commands::delete_selection,
157 vec![key!('d')] => commands::delete_selection,
158 vec![key!('c')] => commands::change_selection,
158 vec![key!('c')] => commands::change_selection,
159− vec![shift!('S')] => commands::split_selection,
160 vec![key!('s')] => commands::split_selection_on_newline,
159 vec![key!('s')] => commands::split_selection_on_newline,
160+ vec![shift!('S')] => commands::split_selection,
161 vec![key!(';')] => commands::collapse_selection,
161 vec![key!(';')] => commands::collapse_selection,
162 // TODO should be alt(;)
162 // TODO should be alt(;)
163 vec![key!('%')] => commands::flip_selections,
163 vec![key!('%')] => commands::flip_selections,