on master help sign in
fix: 2 panics while setting style + off by 1
e2d780fahkrr
helix-core/src/search.rs−1
@@ -41,7 +41,6 @@ pub fn find_nth_prev(
41 inclusive: bool,
41 inclusive: bool,
42) -> Option<usize> {
42) -> Option<usize> {
43 // start searching right before pos
43 // start searching right before pos
44− pos = pos.saturating_sub(1);
45 let mut chars = text.chars_at(pos);
44 let mut chars = text.chars_at(pos);
46
45
47 for _ in 0..n {
46 for _ in 0..n {
helix-term/src/ui/editor.rs+16−2
@@ -261,7 +261,16 @@ impl EditorView {
261 Rect::new(
261 Rect::new(
262 viewport.x + start.col as u16,
262 viewport.x + start.col as u16,
263 viewport.y + start.row as u16,
263 viewport.y + start.row as u16,
264+ // .min is important, because set_style does a
265+ // for i in area.left()..area.right() and
266+ // area.right = x + width !!! which shouldn't be > then surface.area.right()
267+ // This is checked by a debug_assert! in Buffer::index_of
264− ((end.col - start.col) as u16 + 1).min(viewport.width),
268+ ((end.col - start.col) as u16 + 1).min(
269+ surface
270+ .area
271+ .width
272+ .saturating_sub(viewport.x + start.col as u16),
273+ ),
265 1,
274 1,
266 ),
275 ),
267 selection_style,
276 selection_style,
@@ -290,7 +299,12 @@ impl EditorView {
290 );
299 );
291 }
300 }
292 surface.set_style(
301 surface.set_style(
302+ Rect::new(
303+ viewport.x,
293− Rect::new(viewport.x, viewport.y + end.row as u16, end.col as u16, 1),
304+ viewport.y + end.row as u16,
305+ (end.col as u16).min(viewport.width),
306+ 1,
307+ ),
294 selection_style,
308 selection_style,
295 );
309 );
296 }
310 }