From 92ae6bc9a6679c5d49cac48b5e12febbd77e86a3 Mon Sep 17 00:00:00 2001 From: Graicc <33105645+Graicc@users.noreply.github.com> Date: Fri, 7 Oct 2022 12:34:23 -0400 Subject: [PATCH 1/4] Fix 4074 --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 2db5bfcf3019..447ce1def2d8 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2224,7 +2224,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.head == end || last_range.anchor == end) { let transaction = Transaction::change( doc.text(), [(end, end, Some(doc.line_ending.as_str().into()))].into_iter(), From 620a7295cc30d26c0088c79fb6471d69bb818ae6 Mon Sep 17 00:00:00 2001 From: Graicc <33105645+Graicc@users.noreply.github.com> Date: Fri, 7 Oct 2022 17:31:24 -0400 Subject: [PATCH 2/4] Add append cursor position tests --- helix-term/tests/test/movement.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs index e5abb0b0b599..2d14013e2f2c 100644 --- a/helix-term/tests/test/movement.rs +++ b/helix-term/tests/test/movement.rs @@ -86,6 +86,25 @@ async fn cursor_position_newly_opened_file() -> anyhow::Result<()> { Ok(()) } +#[tokio::test] +async fn cursor_position_append_eof() -> anyhow::Result<()> { + test(( + "#[f|]#oo", + "eabar", + helpers::platform_line("#[foobar|]#\n").as_ref() + )) + .await?; + + test(( + "foo#[|]#", + "babar", + 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( From f3363725e7cfb0d1468b897cdf2a7628c06005a2 Mon Sep 17 00:00:00 2001 From: Graicc <33105645+Graicc@users.noreply.github.com> Date: Tue, 11 Oct 2022 01:51:15 -0400 Subject: [PATCH 3/4] Update append cursor tests --- helix-term/tests/test/movement.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs index 2d14013e2f2c..45aae39e1cdc 100644 --- a/helix-term/tests/test/movement.rs +++ b/helix-term/tests/test/movement.rs @@ -88,20 +88,22 @@ async fn cursor_position_newly_opened_file() -> anyhow::Result<()> { #[tokio::test] async fn cursor_position_append_eof() -> anyhow::Result<()> { + // Selection is fowards test(( - "#[f|]#oo", - "eabar", - helpers::platform_line("#[foobar|]#\n").as_ref() + "#[foo|]#", + "abar", + helpers::platform_line("#[foobar|]#\n").as_ref(), )) .await?; - + + // Selection is backwards test(( - "foo#[|]#", - "babar", - helpers::platform_line("#[foobar|]#\n").as_ref() + "#[|foo]#", + "abar", + helpers::platform_line("#[foobar|]#\n").as_ref(), )) .await?; - + Ok(()) } From 47d4a02526e9776cacec801f304dbc370c83e5b7 Mon Sep 17 00:00:00 2001 From: Graicc <33105645+Graicc@users.noreply.github.com> Date: Tue, 11 Oct 2022 22:07:37 -0400 Subject: [PATCH 4/4] Simplify end of file check --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 447ce1def2d8..16db13d6fba8 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2224,7 +2224,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 || last_range.anchor == 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(),