aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-03-31 06:53:31 +0000
committerBlaž Hrastnik2022-03-31 06:59:09 +0000
commitab7885e93423dbfb57e2b6e7589672c67a4666e8 (patch)
treefffdc35430571f019d0bf7e72bc255215543dd7b /helix-term/src
parent4eed4c26e9f72a586f9175c4976d80ba091086e6 (diff)
fix: copy_selection needs to account for to() being exclusive
Fixes #1367 Fixes #1590
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index bd66f26a..3ef72bde 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -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;