on master help sign in
Fix selection rendering, it would be off by 1 if reverse.
e8298a3Blaž Hrastnik
helix-core/src/movement.rs+1−2
@@ -128,8 +128,7 @@ pub fn move_prev_word_start(slice: RopeSlice, mut begin: usize, count: usize) ->
128 }
128 }
129 }
129 }
130
130
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 }))
133}
132}
134
133
135pub fn move_next_word_end(slice: RopeSlice, mut begin: usize, count: usize) -> Option<Range> {
134pub 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 {
233 // TODO: render also if only one of the ranges is in viewport
233 // TODO: render also if only one of the ranges is in viewport
234 let mut start = view.screen_coords_at_pos(doc, text, selection.anchor);
234 let mut start = view.screen_coords_at_pos(doc, text, selection.anchor);
235 let mut end = view.screen_coords_at_pos(doc, text, selection.head);
235 let mut end = view.screen_coords_at_pos(doc, text, selection.head);
236−
236+
237− // cursor
238− if let Some(end) = end {
237+ let head = 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− }
249
238
250 if selection.head < selection.anchor {
239 if selection.head < selection.anchor {
251 std::mem::swap(&mut start, &mut end);
240 std::mem::swap(&mut start, &mut end);
@@ -260,7 +249,7 @@ impl EditorView {
260 Rect::new(
249 Rect::new(
261 viewport.x + start.col as u16,
250 viewport.x + start.col as u16,
262 viewport.y + start.row as u16,
251 viewport.y + start.row as u16,
263− (end.col - start.col) as u16,
252+ (end.col - start.col) as u16 + 1,
264 1,
253 1,
265 ),
254 ),
266 selection_style,
255 selection_style,
@@ -293,6 +282,19 @@ impl EditorView {
293 selection_style,
282 selection_style,
294 );
283 );
295 }
284 }
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+ }
296 }
298 }
297 }
299 }
298
300