Skip to content

Commit

Permalink
Fix backwards selection duplication widening bug (#2945)
Browse files Browse the repository at this point in the history
* Fix backwards selection duplication widening bug

* Add integration tests

* Make tests line-ending agnostic

Make tests line-ending agnostic

Use indoc to fix tests

Fix line-ending on test input
  • Loading branch information
A-Walrus authored Jul 4, 2022
1 parent 244825b commit 2ac1de3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
8 changes: 4 additions & 4 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions helix-term/tests/test/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit 2ac1de3

Please sign in to comment.