on master help sign in
fix: copy_selection needs to account for to() being exclusive

Fixes #1367 Fixes #1590

commitab7885e93423dbfb57e2b6e7589672c67a4666e8 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 31 Mar 2022, 15:53 (5 years ago) parent4eed4c2
1 file changed+10−1
helix-term/src/commands.rs+10−1
helix-term/src/commands.rs+10−1
@@ -1342,8 +1342,17 @@ fn copy_selection_on_line(cx: &mut Context, direction: Direction) {
13421342 let mut primary_index = 0;
13431343 for range in selection.iter() {
13441344 let is_primary = *range == selection.primary();
1345− let head_pos = coords_at_pos(text, range.head);
1345+
1346+ // The range is always head exclusive
1347+ let head = if range.anchor < range.head {
1348+ range.head - 1
1349+ } else {
1350+ range.head
1351+ };
1352+
1353+ let head_pos = coords_at_pos(text, head);
13461354 let anchor_pos = coords_at_pos(text, range.anchor);
1355+
13471356 let height = std::cmp::max(head_pos.row, anchor_pos.row)
13481357 - std::cmp::min(head_pos.row, anchor_pos.row)
13491358 + 1;