on master help sign in
search_next_impl: don't panic on invalid regex (#740)
commit1d04e5938daf178dbbcdb2249f42f8485047d4cf authorLeoi Hung Kin <leoihungkin@outlook.com> dateFri 17 Sep 2021, 16:22 (5 years ago) parent3ff5b00
1 file changed+9−2
helix-term/src/commands.rs+9−2
helix-term/src/commands.rs+9−2
@@ -1154,8 +1154,15 @@ fn search_next_impl(cx: &mut Context, extend: bool) {
11541154 if let Some(query) = registers.read('/') {
11551155 let query = query.last().unwrap();
11561156 let contents = doc.text().slice(..).to_string();
1157− let regex = Regex::new(query).unwrap();
1158− search_impl(doc, view, &contents, &regex, extend);
1157+ if let Ok(regex) = Regex::new(query) {
1158+ search_impl(doc, view, &contents, &regex, extend);
1159+ } else {
1160+ // get around warning `mutable_borrow_reservation_conflict`
1161+ // which will be a hard error in the future
1162+ // see: https://github.com/rust-lang/rust/issues/59159
1163+ let query = query.clone();
1164+ cx.editor.set_error(format!("Invalid regex: {}", query));
1165+ }
11591166 }
11601167}
11611168