diff options
author | Blaž Hrastnik | 2021-04-07 07:57:58 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-04-07 07:57:58 +0000 |
commit | e8298a398c6b018c49025ff3f885e4f5f40b01fd (patch) | |
tree | 84ce25cf9aedde84b043eb8f5a1f2b20475ccf95 /helix-term/src/ui/editor.rs | |
parent | 63e602bda6e6c4381372880f4313aec46170044d (diff) |
Fix selection rendering, it would be off by 1 if reverse.
Diffstat (limited to 'helix-term/src/ui/editor.rs')
-rw-r--r-- | helix-term/src/ui/editor.rs | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 1317a5e7..67f5cf84 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -233,19 +233,8 @@ impl EditorView { // TODO: render also if only one of the ranges is in viewport let mut start = view.screen_coords_at_pos(doc, text, selection.anchor); let mut end = view.screen_coords_at_pos(doc, text, selection.head); - - // cursor - if let Some(end) = end { - surface.set_style( - Rect::new( - viewport.x + end.col as u16, - viewport.y + end.row as u16, - 1, - 1, - ), - cursor_style, - ); - } + + let head = end; if selection.head < selection.anchor { std::mem::swap(&mut start, &mut end); @@ -260,7 +249,7 @@ impl EditorView { Rect::new( viewport.x + start.col as u16, viewport.y + start.row as u16, - (end.col - start.col) as u16, + (end.col - start.col) as u16 + 1, 1, ), selection_style, @@ -293,6 +282,19 @@ impl EditorView { selection_style, ); } + + // cursor + if let Some(head) = head { + surface.set_style( + Rect::new( + viewport.x + head.col as u16, + viewport.y + head.row as u16, + 1, + 1, + ), + cursor_style, + ); + } } } |