diff options
author | ahkrr | 2021-06-06 19:32:14 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-07 00:15:08 +0000 |
commit | e2d780f993201a79261bc6bd869c8b4f1dc410ce (patch) | |
tree | 1c301dda35dc5148ba4e41dffab9499d8ea047e6 /helix-term/src/ui | |
parent | 843c2cdebd50cfe066c88571eb754c465cda2f60 (diff) |
fix: 2 panics while setting style + off by 1
The panics would occur because set_style
would draw outside of the the surface.
Both occured using `find_prev` or `till_prev`
In my case the first panic! would appear
in a terminal with around 80 columns
in helix/README.md going to the end of the file
with `geglf(`
the second with `geglfX`
The off by one fix ensures that `find_nth_prev`
starts at the first character to the left
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/editor.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index f47d6c26..8ce9cdc8 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -261,7 +261,16 @@ impl EditorView { Rect::new( viewport.x + start.col as u16, viewport.y + start.row as u16, - ((end.col - start.col) as u16 + 1).min(viewport.width), + // .min is important, because set_style does a + // for i in area.left()..area.right() and + // area.right = x + width !!! which shouldn't be > then surface.area.right() + // This is checked by a debug_assert! in Buffer::index_of + ((end.col - start.col) as u16 + 1).min( + surface + .area + .width + .saturating_sub(viewport.x + start.col as u16), + ), 1, ), selection_style, @@ -290,7 +299,12 @@ impl EditorView { ); } surface.set_style( - Rect::new(viewport.x, viewport.y + end.row as u16, end.col as u16, 1), + Rect::new( + viewport.x, + viewport.y + end.row as u16, + (end.col as u16).min(viewport.width), + 1, + ), selection_style, ); } |