From 5d1f6b9eb6755327233dde8cc8df0514221e2a90 Mon Sep 17 00:00:00 2001 From: Graic <33105645+Graicc@users.noreply.github.com> Date: Wed, 12 Oct 2022 09:34:35 -0400 Subject: [PATCH] Fix append cursor location when selection anchor is at end of document (#4147) --- helix-term/src/commands.rs | 2 +- helix-term/tests/test/movement.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 444091b69ddae..f90a2689bf2d3 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2229,7 +2229,7 @@ fn append_mode(cx: &mut Context) { .iter() .last() .expect("selection should always have at least one range"); - if !last_range.is_empty() && last_range.head == end { + if !last_range.is_empty() && last_range.to() == end { let transaction = Transaction::change( doc.text(), [(end, end, Some(doc.line_ending.as_str().into()))].into_iter(), diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs index e5abb0b0b599e..45aae39e1cdcf 100644 --- a/helix-term/tests/test/movement.rs +++ b/helix-term/tests/test/movement.rs @@ -86,6 +86,27 @@ async fn cursor_position_newly_opened_file() -> anyhow::Result<()> { Ok(()) } +#[tokio::test] +async fn cursor_position_append_eof() -> anyhow::Result<()> { + // Selection is fowards + test(( + "#[foo|]#", + "abar", + helpers::platform_line("#[foobar|]#\n").as_ref(), + )) + .await?; + + // Selection is backwards + test(( + "#[|foo]#", + "abar", + helpers::platform_line("#[foobar|]#\n").as_ref(), + )) + .await?; + + Ok(()) +} + #[tokio::test] async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> { test_with_config(