aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-03 08:55:56 +0000
committerBlaž Hrastnik2021-03-03 08:55:56 +0000
commit4c6611f96b6a7d3e27bfb0c8e43d49f62dde493b (patch)
tree2adf5e8293d37aa3cb41de1b8da9a58dd616d09e
parenta21d96e7293e32c0d20e8548a65fdd31f92b642d (diff)
commands: Stop select_regex from breaking when no matches.
-rw-r--r--helix-term/src/commands.rs8
-rw-r--r--helix-term/src/ui/mod.rs5
2 files changed, 8 insertions, 5 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index bbd78092..cb811c98 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -307,11 +307,9 @@ pub fn select_all(cx: &mut Context) {
pub fn select_regex(cx: &mut Context) {
let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
let text = doc.text().slice(..);
- // TODO: if select on matches returns empty range, we need to abort
- // if regex empty or no matches, return
- let selection =
- selection::select_on_matches(text, doc.selection(), &regex).expect("no matches");
- doc.set_selection(selection);
+ if let Some(selection) = selection::select_on_matches(text, doc.selection(), &regex) {
+ doc.set_selection(selection);
+ }
});
cx.push_layer(Box::new(prompt));
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index 463ac368..593da3ae 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -45,6 +45,11 @@ pub fn regex_prompt(
//
}
PromptEvent::Update => {
+ // skip empty input, TODO: trigger default
+ if input.is_empty() {
+ return;
+ }
+
match Regex::new(input) {
Ok(regex) => {
let view = &mut editor.view_mut();