diff options
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 8 | ||||
-rw-r--r-- | helix-term/tests/test/commands.rs | 40 |
2 files changed, 44 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index df4867fc..c9e35062 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1411,16 +1411,16 @@ fn copy_selection_on_line(cx: &mut Context, direction: Direction) { let is_primary = *range == selection.primary(); // The range is always head exclusive - let head = if range.anchor < range.head { - range.head - 1 + let (head, anchor) = if range.anchor < range.head { + (range.head - 1, range.anchor) } else { - range.head + (range.head, range.anchor - 1) }; let tab_width = doc.tab_width(); let head_pos = visual_coords_at_pos(text, head, tab_width); - let anchor_pos = visual_coords_at_pos(text, range.anchor, tab_width); + let anchor_pos = visual_coords_at_pos(text, anchor, tab_width); let height = std::cmp::max(head_pos.row, anchor_pos.row) - std::cmp::min(head_pos.row, anchor_pos.row) diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 0cd79bc7..f7ce9af0 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -91,3 +91,43 @@ async fn test_buffer_close_concurrent() -> anyhow::Result<()> { Ok(()) } + +#[tokio::test] +async fn test_selection_duplication() -> anyhow::Result<()> { + // Forward + test(( + platform_line(indoc! {"\ + #[lo|]#rem + ipsum + dolor + "}) + .as_str(), + "CC", + platform_line(indoc! {"\ + #(lo|)#rem + #(ip|)#sum + #[do|]#lor + "}) + .as_str(), + )) + .await?; + + // Backward + test(( + platform_line(indoc! {"\ + #[|lo]#rem + ipsum + dolor + "}) + .as_str(), + "CC", + platform_line(indoc! {"\ + #(|lo)#rem + #(|ip)#sum + #[|do]#lor + "}) + .as_str(), + )) + .await?; + Ok(()) +} |