Skip to content

Commit

Permalink
fix: copy_selection needs to account for to() being exclusive
Browse files Browse the repository at this point in the history
Fixes #1367
Fixes #1590
  • Loading branch information
archseer committed Mar 31, 2022
1 parent 4eed4c2 commit ab7885e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion helix-term/src/commands.rs
Expand Up @@ -1342,8 +1342,17 @@ fn copy_selection_on_line(cx: &mut Context, direction: Direction) {
let mut primary_index = 0;
for range in selection.iter() {
let is_primary = *range == selection.primary();
let head_pos = coords_at_pos(text, range.head);

// The range is always head exclusive
let head = if range.anchor < range.head {
range.head - 1
} else {
range.head
};

let head_pos = coords_at_pos(text, head);
let anchor_pos = coords_at_pos(text, range.anchor);

let height = std::cmp::max(head_pos.row, anchor_pos.row)
- std::cmp::min(head_pos.row, anchor_pos.row)
+ 1;
Expand Down

1 comment on commit ab7885e

@the-mikedavis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archseer I think this caused a regression with how Shiftc usually works. It looks like now the head gets removed consistently:

https://asciinema.org/a/483103

Please sign in to comment.