@@ -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 }