diff --git a/helix-core/src/surround.rs b/helix-core/src/surround.rs index aa12a4bbe2870..36a03e4560ce7 100644 --- a/helix-core/src/surround.rs +++ b/helix-core/src/surround.rs @@ -62,7 +62,7 @@ pub fn find_nth_closest_pairs_pos( let mut stack = Vec::with_capacity(2); let pos = range.from(); - let mut close_pos = pos - 1; + let mut close_pos = pos.saturating_sub(1); for ch in text.chars_at(pos) { close_pos += 1; diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs index 521fd57711ff5..2fb46609cffd7 100644 --- a/helix-term/tests/test/movement.rs +++ b/helix-term/tests/test/movement.rs @@ -81,6 +81,10 @@ async fn surround_by_character() -> anyhow::Result<()> { #[tokio::test] async fn surround_pair() -> anyhow::Result<()> { + // Works at first character of buffer + // TODO: Adjust test when opening pair failure is fixed + test(("#[(|]#something)", "mim", "#[(|]#something)")).await?; + // Inside a valid pair selects pair test(("some (#[t|]#ext) here", "mim", "some (#[text|]#) here")).await?;