fix: handle pair not found error gracefully

This commit is contained in:
Nikita Revenco 2024-11-13 19:59:43 +00:00
parent 74b8ca9c72
commit b2f1bb8de9
2 changed files with 24 additions and 11 deletions

View File

@ -360,11 +360,23 @@ 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)?;
forward_tags.push((forward_tag_range, forward_tag_name)); match next_tag_maybe {
previous_forward_pos = forward_search_idx; Ok((forward_tag_range, forward_tag_name, forward_search_idx)) => {
forward_tags.push((forward_tag_range, forward_tag_name));
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![];
@ -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;
} }
} }

View File

@ -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) {