From 2c070cb9cdb49ce5a64ba318927a0a7b40fffcc8 Mon Sep 17 00:00:00 2001 From: Daniel Poulin Date: Sun, 18 Sep 2022 23:41:29 -0400 Subject: [PATCH] Fix out of bounds error --- helix-core/src/surround.rs | 2 +- helix-term/tests/test/movement.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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?;