mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-19 13:37:06 +04:00
Fix selection rendering, it would be off by 1 if reverse.
This commit is contained in:
parent
63e602bda6
commit
e8298a398c
@ -128,8 +128,7 @@ pub fn move_prev_word_start(slice: RopeSlice, mut begin: usize, count: usize) ->
|
||||
}
|
||||
}
|
||||
|
||||
// we want to include begin
|
||||
Some(Range::new(begin + 1, if with_end { end } else { end + 1 }))
|
||||
Some(Range::new(begin, if with_end { end } else { end + 1 }))
|
||||
}
|
||||
|
||||
pub fn move_next_word_end(slice: RopeSlice, mut begin: usize, count: usize) -> Option<Range> {
|
||||
|
@ -233,19 +233,8 @@ pub fn render_buffer(
|
||||
// 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 @@ pub fn render_buffer(
|
||||
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 @@ pub fn render_buffer(
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user