@@ -282,6 +282,19 @@ pub fn extend_line_down(cx: &mut Context) {
282282 doc.set_selection(selection);
283283}
284284
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);
290+ });
291+ cx.callback = Some(Box::new(
292+ move |compositor: &mut Compositor, editor: &mut Editor| {
293+ compositor.push(Box::new(prompt));
294+ },
295+ ));
296+}
297+
285298pub fn split_selection(cx: &mut Context) {
286299 // TODO: this needs to store initial selection state, revert on esc, confirm on enter
287300 // 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) {
298311
299312 let snapshot = cx.doc().state.clone();
300313
301− let prompt = Prompt::new(
302− "split:".to_string(),
303− |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
304− move |editor: &mut Editor, input: &str, event: PromptEvent| {
305− match event {
306− PromptEvent::Abort => {
307− // revert state
308− let doc = &mut editor.view_mut().doc;
309− doc.state = snapshot.clone();
310− }
311− PromptEvent::Validate => {
312− //
313− }
314− PromptEvent::Update => {
315− match Regex::new(input) {
316− Ok(regex) => {
317− let doc = &mut editor.view_mut().doc;
318−
319− // revert state to what it was before the last update
320− doc.state = snapshot.clone();
321−
322− let text = &doc.text().slice(..);
323− let selection =
324− selection::split_on_matches(text, doc.selection(), ®ex);
325− doc.set_selection(selection);
326− }
327− Err(_err) => (), // TODO: mark command line as error
328− }
329− }
330− }
331− },
332− );
314+ let prompt = ui::regex_prompt(cx, "split:".to_string(), |doc, regex| {
315+ let text = &doc.text().slice(..);
316+ let selection = selection::split_on_matches(text, doc.selection(), ®ex);
317+ doc.set_selection(selection);
318+ });
333319
334320 cx.callback = Some(Box::new(
335321 move |compositor: &mut Compositor, editor: &mut Editor| {