diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e6cbed2ce34c..d7d87b5a159e 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1617,6 +1617,10 @@ fn copy_selection_on_line(cx: &mut Context, direction: Direction) { sels += 1; } + if anchor_row == 0 && head_row == 0 { + break; + } + i += 1; } } diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 2ca9e3957a7b..e8d16bfaf2be 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -132,6 +132,70 @@ async fn test_selection_duplication() -> anyhow::Result<()> { .as_str(), )) .await?; + + // Copy the selection to previous line, skipping the first line in the file + test(( + platform_line(indoc! {"\ + test + #[testitem|]# + "}) + .as_str(), + "", + platform_line(indoc! {"\ + test + #[testitem|]# + "}) + .as_str(), + )) + .await?; + + // Copy the selection to previous line, including the first line in the file + test(( + platform_line(indoc! {"\ + test + #[test|]# + "}) + .as_str(), + "", + platform_line(indoc! {"\ + #[test|]# + #(test|)# + "}) + .as_str(), + )) + .await?; + + // Copy the selection to next line, skipping the last line in the file + test(( + platform_line(indoc! {"\ + #[testitem|]# + test + "}) + .as_str(), + "C", + platform_line(indoc! {"\ + #[testitem|]# + test + "}) + .as_str(), + )) + .await?; + + // Copy the selection to next line, including the last line in the file + test(( + platform_line(indoc! {"\ + #[test|]# + test + "}) + .as_str(), + "C", + platform_line(indoc! {"\ + #(test|)# + #[test|]# + "}) + .as_str(), + )) + .await?; Ok(()) }