on master help sign in
Fix selection rendering, it would be off by 1 if reverse.
commite8298a398c6b018c49025ff3f885e4f5f40b01fd authorBlaž Hrastnik <blaz@mxxn.io> dateWed 7 Apr 2021, 16:57 (6 years ago) parent63e602b
2 files changed+17−16
helix-core/src/movement.rs+1−2 helix-term/src/ui/editor.rs+16−14
helix-core/src/movement.rs+1−2
@@ -128,8 +128,7 @@ pub fn move_prev_word_start(slice: RopeSlice, mut begin: usize, count: usize) ->
128128 }
129129 }
130130
131− // we want to include begin
132− Some(Range::new(begin + 1, if with_end { end } else { end + 1 }))
131+ Some(Range::new(begin, if with_end { end } else { end + 1 }))
133132}
134133
135134pub fn move_next_word_end(slice: RopeSlice, mut begin: usize, count: usize) -> Option<Range> {
helix-term/src/ui/editor.rs+16−14
@@ -233,19 +233,8 @@ impl EditorView {
233233 // TODO: render also if only one of the ranges is in viewport
234234 let mut start = view.screen_coords_at_pos(doc, text, selection.anchor);
235235 let mut end = view.screen_coords_at_pos(doc, text, selection.head);
236−
237− // cursor
238− if let Some(end) = end {
239− surface.set_style(
240− Rect::new(
241− viewport.x + end.col as u16,
242− viewport.y + end.row as u16,
243− 1,
244− 1,
245− ),
246− cursor_style,
247− );
248− }
236+
237+ let head = end;
249238
250239 if selection.head < selection.anchor {
251240 std::mem::swap(&mut start, &mut end);
@@ -260,7 +249,7 @@ impl EditorView {
260249 Rect::new(
261250 viewport.x + start.col as u16,
262251 viewport.y + start.row as u16,
263− (end.col - start.col) as u16,
252+ (end.col - start.col) as u16 + 1,
264253 1,
265254 ),
266255 selection_style,
@@ -293,6 +282,19 @@ impl EditorView {
293282 selection_style,
294283 );
295284 }
285+
286+ // cursor
287+ if let Some(head) = head {
288+ surface.set_style(
289+ Rect::new(
290+ viewport.x + head.col as u16,
291+ viewport.y + head.row as u16,
292+ 1,
293+ 1,
294+ ),
295+ cursor_style,
296+ );
297+ }
296298 }
297299 }
298300