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.
pull/104/head
Ivan Tham 4 years ago committed by Blaž Hrastnik
parent fdb5bfafae
commit 29b9eed33c

@ -306,6 +306,7 @@ impl EditorView {
), ),
cursor_style, cursor_style,
); );
// TODO: set cursor position for IME
if let Some(syntax) = doc.syntax() { if let Some(syntax) = doc.syntax() {
use helix_core::match_brackets; use helix_core::match_brackets;
let pos = doc.selection(view.id).cursor(); let pos = doc.selection(view.id).cursor();
@ -313,6 +314,10 @@ impl EditorView {
if let Some(pos) = pos { if let Some(pos) = pos {
let pos = view.screen_coords_at_pos(doc, text, pos); let pos = view.screen_coords_at_pos(doc, text, pos);
if let Some(pos) = pos { if let Some(pos) = pos {
// this only prevents panic due to painting selection too far
// TODO: prevent painting when scroll past x or in gutter
// TODO: use a more correct width check
if (pos.col as u16) < viewport.width {
let style = Style::default().add_modifier(Modifier::REVERSED); let style = Style::default().add_modifier(Modifier::REVERSED);
surface surface
.get_mut(pos.col as u16 + OFFSET, pos.row as u16) .get_mut(pos.col as u16 + OFFSET, pos.row as u16)
@ -323,6 +328,7 @@ impl EditorView {
} }
} }
} }
}
// render gutters // render gutters

Loading…
Cancel
Save