aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--helix-core/src/surround.rs3
-rw-r--r--helix-term/tests/test/movement.rs54
2 files changed, 56 insertions, 1 deletions
diff --git a/helix-core/src/surround.rs b/helix-core/src/surround.rs
index b96cce5a..513f8749 100644
--- a/helix-core/src/surround.rs
+++ b/helix-core/src/surround.rs
@@ -260,7 +260,8 @@ pub fn get_surround_pos(
if change_pos.contains(&open_pos) || change_pos.contains(&close_pos) {
return Err(Error::CursorOverlap);
}
- change_pos.extend_from_slice(&[open_pos, close_pos]);
+ // ensure the positions are always paired in the forward direction
+ change_pos.extend_from_slice(&[open_pos.min(close_pos), close_pos.max(open_pos)]);
}
Ok(change_pos)
}
diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs
index e3c2668d..0873edbe 100644
--- a/helix-term/tests/test/movement.rs
+++ b/helix-term/tests/test/movement.rs
@@ -552,3 +552,57 @@ async fn find_char_line_ending() -> anyhow::Result<()> {
Ok(())
}
+
+#[tokio::test(flavor = "multi_thread")]
+async fn test_surround_replace() -> anyhow::Result<()> {
+ test((
+ platform_line(indoc! {"\
+ (#[|a]#)
+ "}),
+ "mrm{",
+ platform_line(indoc! {"\
+ {#[|a]#}
+ "}),
+ ))
+ .await?;
+
+ test((
+ platform_line(indoc! {"\
+ (#[a|]#)
+ "}),
+ "mrm{",
+ platform_line(indoc! {"\
+ {#[a|]#}
+ "}),
+ ))
+ .await?;
+
+ Ok(())
+}
+
+#[tokio::test(flavor = "multi_thread")]
+async fn test_surround_delete() -> anyhow::Result<()> {
+ test((
+ platform_line(indoc! {"\
+ (#[|a]#)
+ "}),
+ "mdm",
+ platform_line(indoc! {"\
+ #[|a]#
+ "}),
+ ))
+ .await?;
+
+ test((
+ platform_line(indoc! {"\
+ (#[a|]#)
+ "}),
+ "mdm",
+ platform_line(indoc! {"\
+ #[a|]#
+ "}),
+ ))
+ .await?;
+
+ Ok(())
+}