split_selection

pull/7/head
Blaž Hrastnik 4 years ago
parent f92998a14b
commit 2bfdcede32

@ -262,23 +262,26 @@ pub fn split_selection(cx: &mut Context) {
// # update state // # update state
// } // }
let prompt = Prompt::new( cx.callback = Some(Box::new(|compositor: &mut Compositor| {
"split:".to_string(), let prompt = Prompt::new(
|input: &str| Vec::new(), // TODO: use Option here? "split:".to_string(),
|editor: &mut Editor, input: &str| { |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
match Regex::new(input) { |editor: &mut Editor, input: &str| {
Ok(regex) => { match Regex::new(input) {
let view = editor.view_mut().unwrap(); Ok(regex) => {
let text = &view.doc.text().slice(..); let view = editor.view_mut().unwrap();
let selection = selection::split_on_matches(text, view.doc.selection(), &regex); let text = &view.doc.text().slice(..);
view.doc.set_selection(selection); let selection =
selection::split_on_matches(text, view.doc.selection(), &regex);
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) { pub fn split_selection_on_newline(cx: &mut Context) {

@ -156,8 +156,8 @@ pub fn default() -> Keymaps {
vec![key!('o')] => commands::open_below, vec![key!('o')] => commands::open_below,
vec![key!('d')] => commands::delete_selection, vec![key!('d')] => commands::delete_selection,
vec![key!('c')] => commands::change_selection, vec![key!('c')] => commands::change_selection,
vec![shift!('S')] => commands::split_selection,
vec![key!('s')] => commands::split_selection_on_newline, vec![key!('s')] => commands::split_selection_on_newline,
vec![shift!('S')] => commands::split_selection,
vec![key!(';')] => commands::collapse_selection, vec![key!(';')] => commands::collapse_selection,
// TODO should be alt(;) // TODO should be alt(;)
vec![key!('%')] => commands::flip_selections, vec![key!('%')] => commands::flip_selections,

Loading…
Cancel
Save