@@ -282,6 +282,19 @@ pub fn extend_line_down(cx: &mut Context) {
282 doc.set_selection(selection);
282 doc.set_selection(selection);
285+pub fn select_regex(cx: &mut Context) {
286+ let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
287+ let text = &doc.text().slice(..);
288+ let selection = selection::select_on_matches(text, doc.selection(), ®ex);
289+ doc.set_selection(selection);
291+ cx.callback = Some(Box::new(
292+ move |compositor: &mut Compositor, editor: &mut Editor| {
293+ compositor.push(Box::new(prompt));
285pub fn split_selection(cx: &mut Context) {
298pub fn split_selection(cx: &mut Context) {
286 // TODO: this needs to store initial selection state, revert on esc, confirm on enter
299 // TODO: this needs to store initial selection state, revert on esc, confirm on enter
287 // needs to also call the callback function per input change, not just final time.
300 // needs to also call the callback function per input change, not just final time.
@@ -298,38 +311,11 @@ pub fn split_selection(cx: &mut Context) {
299 let snapshot = cx.doc().state.clone();
312 let snapshot = cx.doc().state.clone();
301− let prompt = Prompt::new(
302− "split:".to_string(),
314+ let prompt = ui::regex_prompt(cx, "split:".to_string(), |doc, regex| {
303− |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
304− move |editor: &mut Editor, input: &str, event: PromptEvent| {
306− PromptEvent::Abort => {
308− let doc = &mut editor.view_mut().doc;
309− doc.state = snapshot.clone();
311− PromptEvent::Validate => {
314− PromptEvent::Update => {
315− match Regex::new(input) {
317− let doc = &mut editor.view_mut().doc;
319− // revert state to what it was before the last update
320− doc.state = snapshot.clone();
322− let text = &doc.text().slice(..);
315+ let text = &doc.text().slice(..);
324− selection::split_on_matches(text, doc.selection(), ®ex);
316+ let selection = selection::split_on_matches(text, doc.selection(), ®ex);
325− doc.set_selection(selection);
317+ doc.set_selection(selection);
327− Err(_err) => (), // TODO: mark command line as error
334 cx.callback = Some(Box::new(
320 cx.callback = Some(Box::new(
335 move |compositor: &mut Compositor, editor: &mut Editor| {
321 move |compositor: &mut Compositor, editor: &mut Editor| {