on master help sign in
Fix panic paint mysterious matching pair

When the matching pair is out of bounds it still paints it causing an out of bound panic. A dirty fix since it still have some issue, at least it does not panic now.

commit29b9eed33c07c99fb9345a6832d3431157981e52 authorIvan Tham <pickfire@riseup.net> dateFri 4 Jun 2021, 01:46 (5 years ago) parentfdb5bfa
1 file changed+10−4
helix-term/src/ui/editor.rs+10−4
helix-term/src/ui/editor.rs+10−4
@@ -306,6 +306,7 @@ impl EditorView {
306306 ),
307307 cursor_style,
308308 );
309+ // TODO: set cursor position for IME
309310 if let Some(syntax) = doc.syntax() {
310311 use helix_core::match_brackets;
311312 let pos = doc.selection(view.id).cursor();
@@ -313,10 +314,15 @@ impl EditorView {
313314 if let Some(pos) = pos {
314315 let pos = view.screen_coords_at_pos(doc, text, pos);
315316 if let Some(pos) = pos {
316− let style = Style::default().add_modifier(Modifier::REVERSED);
317− surface
318− .get_mut(pos.col as u16 + OFFSET, pos.row as u16)
319− .set_style(style);
317+ // this only prevents panic due to painting selection too far
318+ // TODO: prevent painting when scroll past x or in gutter
319+ // TODO: use a more correct width check
320+ if (pos.col as u16) < viewport.width {
321+ let style = Style::default().add_modifier(Modifier::REVERSED);
322+ surface
323+ .get_mut(pos.col as u16 + OFFSET, pos.row as u16)
324+ .set_style(style);
325+ }
320326 }
321327 }
322328 }