on master help sign in
Fix backwards selection duplication widening bug (#2945)

* 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

commit2ac1de305e10238a2e7ed8c0d66f3fa78566dbaa authorA-Walrus <58790821+A-Walrus@users.noreply.github.com> dateTue 5 Jul 2022, 01:51 (4 years ago) parent244825b
2 files changed+44−4
helix-term/src/commands.rs+4−4 helix-term/tests/test/commands.rs+40
helix-term/src/commands.rs+4−4
@@ -1411,16 +1411,16 @@ fn copy_selection_on_line(cx: &mut Context, direction: Direction) {
14111411 let is_primary = *range == selection.primary();
14121412
14131413 // The range is always head exclusive
1414− let head = if range.anchor < range.head {
1415− range.head - 1
1414+ let (head, anchor) = if range.anchor < range.head {
1415+ (range.head - 1, range.anchor)
14161416 } else {
1417− range.head
1417+ (range.head, range.anchor - 1)
14181418 };
14191419
14201420 let tab_width = doc.tab_width();
14211421
14221422 let head_pos = visual_coords_at_pos(text, head, tab_width);
1423− let anchor_pos = visual_coords_at_pos(text, range.anchor, tab_width);
1423+ let anchor_pos = visual_coords_at_pos(text, anchor, tab_width);
14241424
14251425 let height = std::cmp::max(head_pos.row, anchor_pos.row)
14261426 - std::cmp::min(head_pos.row, anchor_pos.row)
helix-term/tests/test/commands.rs+40
@@ -91,3 +91,43 @@ async fn test_buffer_close_concurrent() -> anyhow::Result<()> {
9191
9292 Ok(())
9393}
94+
95+#[tokio::test]
96+async fn test_selection_duplication() -> anyhow::Result<()> {
97+ // Forward
98+ test((
99+ platform_line(indoc! {"\
100+ #[lo|]#rem
101+ ipsum
102+ dolor
103+ "})
104+ .as_str(),
105+ "CC",
106+ platform_line(indoc! {"\
107+ #(lo|)#rem
108+ #(ip|)#sum
109+ #[do|]#lor
110+ "})
111+ .as_str(),
112+ ))
113+ .await?;
114+
115+ // Backward
116+ test((
117+ platform_line(indoc! {"\
118+ #[|lo]#rem
119+ ipsum
120+ dolor
121+ "})
122+ .as_str(),
123+ "CC",
124+ platform_line(indoc! {"\
125+ #(|lo)#rem
126+ #(|ip)#sum
127+ #[|do]#lor
128+ "})
129+ .as_str(),
130+ ))
131+ .await?;
132+ Ok(())
133+}