fix: handle pair not found error gracefully

pull/12055/head
Nikita Revenco 2 weeks ago
parent 74b8ca9c72
commit b2f1bb8de9

@ -360,12 +360,24 @@ fn find_nth_nearest_tag(
while (previous_forward_pos - cursor_pos) < SEARCH_CHARS while (previous_forward_pos - cursor_pos) < SEARCH_CHARS
&& previous_forward_pos < forward_text.len_chars() && previous_forward_pos < forward_text.len_chars()
{ {
let (forward_tag_range, forward_tag_name, forward_search_idx) = let next_tag_maybe = find_next_tag(forward_text, previous_forward_pos, skip);
find_next_tag(forward_text, previous_forward_pos, skip)?;
match next_tag_maybe {
Ok((forward_tag_range, forward_tag_name, forward_search_idx)) => {
forward_tags.push((forward_tag_range, forward_tag_name)); forward_tags.push((forward_tag_range, forward_tag_name));
previous_forward_pos = forward_search_idx; previous_forward_pos = forward_search_idx;
} }
Err(err) => match err {
Error::PairNotFound => {
break;
}
other_error => {
// Handle other errors
return Err(other_error);
}
},
}
}
let mut backward_tags = vec![]; let mut backward_tags = vec![];
let mut previous_backward_pos = cursor_pos; let mut previous_backward_pos = cursor_pos;
@ -510,6 +522,7 @@ fn find_next_tag(
return Ok((range, possible_tag_name, cursor_pos)); return Ok((range, possible_tag_name, cursor_pos));
} else { } else {
log::error!("BREAKING!");
break; break;
} }
} }

@ -5716,13 +5716,13 @@ fn surround_replace(cx: &mut Context) {
let selection = doc.selection(view.id); let selection = doc.selection(view.id);
if false { if false {
let change_pos = match surround::get_surround_pos_tag(text, selection, layer) { // let change_pos = match surround::get_surround_pos_tag(text, selection, layer) {
Ok(c) => c, // Ok(c) => c,
Err(err) => { // Err(err) => {
cx.editor.set_error(err.to_string()); // cx.editor.set_error(err.to_string());
return; // return;
} // }
}; // };
// TODO: add back the logic for other surround changes // TODO: add back the logic for other surround changes
} else { } else {
let change_pos = match surround::get_surround_pos_tag(text, selection, layer) { let change_pos = match surround::get_surround_pos_tag(text, selection, layer) {

Loading…
Cancel
Save