aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorLeoi Hung Kin2021-09-17 08:22:17 +0000
committerGitHub2021-09-17 08:22:17 +0000
commit1d04e5938daf178dbbcdb2249f42f8485047d4cf (patch)
treeabd0dd31a302a312433e6e540a5c72e26a36620c /helix-term
parent3ff5b001ac721606b68a594958abeee8832a023e (diff)
search_next_impl: don't panic on invalid regex (#740)
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index d2a838ba..703b92d1 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1154,8 +1154,15 @@ fn search_next_impl(cx: &mut Context, extend: bool) {
if let Some(query) = registers.read('/') {
let query = query.last().unwrap();
let contents = doc.text().slice(..).to_string();
- let regex = Regex::new(query).unwrap();
- search_impl(doc, view, &contents, &regex, extend);
+ if let Ok(regex) = Regex::new(query) {
+ search_impl(doc, view, &contents, &regex, extend);
+ } else {
+ // get around warning `mutable_borrow_reservation_conflict`
+ // which will be a hard error in the future
+ // see: https://github.com/rust-lang/rust/issues/59159
+ let query = query.clone();
+ cx.editor.set_error(format!("Invalid regex: {}", query));
+ }
}
}