From b2f1bb8de9f65929f31ee4a459aa0ec01240fd0b Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Wed, 13 Nov 2024 19:59:43 +0000 Subject: [PATCH] fix: handle pair not found error gracefully --- helix-core/src/surround.rs | 21 +++++++++++++++++---- helix-term/src/commands.rs | 14 +++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/helix-core/src/surround.rs b/helix-core/src/surround.rs index 50f77c6dc..1ccf6c2ea 100644 --- a/helix-core/src/surround.rs +++ b/helix-core/src/surround.rs @@ -360,11 +360,23 @@ fn find_nth_nearest_tag( while (previous_forward_pos - cursor_pos) < SEARCH_CHARS && previous_forward_pos < forward_text.len_chars() { - let (forward_tag_range, forward_tag_name, forward_search_idx) = - find_next_tag(forward_text, previous_forward_pos, skip)?; + let next_tag_maybe = find_next_tag(forward_text, previous_forward_pos, skip); - forward_tags.push((forward_tag_range, forward_tag_name)); - previous_forward_pos = forward_search_idx; + match next_tag_maybe { + 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![]; @@ -510,6 +522,7 @@ fn find_next_tag( return Ok((range, possible_tag_name, cursor_pos)); } else { + log::error!("BREAKING!"); break; } } diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 40fbd3051..0e2a85110 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5716,13 +5716,13 @@ fn surround_replace(cx: &mut Context) { let selection = doc.selection(view.id); if false { - let change_pos = match surround::get_surround_pos_tag(text, selection, layer) { - Ok(c) => c, - Err(err) => { - cx.editor.set_error(err.to_string()); - return; - } - }; + // let change_pos = match surround::get_surround_pos_tag(text, selection, layer) { + // Ok(c) => c, + // Err(err) => { + // cx.editor.set_error(err.to_string()); + // return; + // } + // }; // TODO: add back the logic for other surround changes } else { let change_pos = match surround::get_surround_pos_tag(text, selection, layer) {