on master help sign in
search_next_impl: don't panic on invalid regex (#740)
1d04e59Leoi Hung Kin
helix-term/src/commands.rs+9−2
@@ -1154,8 +1154,15 @@ fn search_next_impl(cx: &mut Context, extend: bool) {
1154 if let Some(query) = registers.read('/') {
1154 if let Some(query) = registers.read('/') {
1155 let query = query.last().unwrap();
1155 let query = query.last().unwrap();
1156 let contents = doc.text().slice(..).to_string();
1156 let contents = doc.text().slice(..).to_string();
1157− let regex = Regex::new(query).unwrap();
1157+ if let Ok(regex) = Regex::new(query) {
1158− search_impl(doc, view, &contents, &regex, extend);
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+ }
1159 }
1166 }
1160}
1167}
1161
1168