on master help sign in
commands: Stop select_regex from breaking when no matches.
commit4c6611f96b6a7d3e27bfb0c8e43d49f62dde493b authorBlaž Hrastnik <blaz@mxxn.io> dateWed 3 Mar 2021, 17:55 (6 years ago) parenta21d96e
2 files changed+8−5
helix-term/src/commands.rs+3−5 helix-term/src/ui/mod.rs+5
helix-term/src/commands.rs+3−5
@@ -307,11 +307,9 @@ pub fn select_all(cx: &mut Context) {
307307pub fn select_regex(cx: &mut Context) {
308308 let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
309309 let text = doc.text().slice(..);
310− // TODO: if select on matches returns empty range, we need to abort
311− // if regex empty or no matches, return
312− let selection =
313− selection::select_on_matches(text, doc.selection(), &regex).expect("no matches");
314− doc.set_selection(selection);
310+ if let Some(selection) = selection::select_on_matches(text, doc.selection(), &regex) {
311+ doc.set_selection(selection);
312+ }
315313 });
316314
317315 cx.push_layer(Box::new(prompt));
helix-term/src/ui/mod.rs+5
@@ -45,6 +45,11 @@ pub fn regex_prompt(
4545 //
4646 }
4747 PromptEvent::Update => {
48+ // skip empty input, TODO: trigger default
49+ if input.is_empty() {
50+ return;
51+ }
52+
4853 match Regex::new(input) {
4954 Ok(regex) => {
5055 let view = &mut editor.view_mut();