on master help sign in
commands: Stop select_regex from breaking when no matches.
4c6611fBlaž Hrastnik
helix-term/src/commands.rs+3−5
@@ -307,11 +307,9 @@ pub fn select_all(cx: &mut Context) {
307pub fn select_regex(cx: &mut Context) {
307pub fn select_regex(cx: &mut Context) {
308 let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
308 let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
309 let text = doc.text().slice(..);
309 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");
310+ if let Some(selection) = selection::select_on_matches(text, doc.selection(), &regex) {
314− doc.set_selection(selection);
311+ doc.set_selection(selection);
312+ }
315 });
313 });
316
314
317 cx.push_layer(Box::new(prompt));
315 cx.push_layer(Box::new(prompt));
helix-term/src/ui/mod.rs+5
@@ -45,6 +45,11 @@ pub fn regex_prompt(
45 //
45 //
46 }
46 }
47 PromptEvent::Update => {
47 PromptEvent::Update => {
48+ // skip empty input, TODO: trigger default
49+ if input.is_empty() {
50+ return;
51+ }
52+
48 match Regex::new(input) {
53 match Regex::new(input) {
49 Ok(regex) => {
54 Ok(regex) => {
50 let view = &mut editor.view_mut();
55 let view = &mut editor.view_mut();