@@ -24,7 +24,7 @@ use helix_view::{
2424 keyboard::{KeyCode, KeyModifiers},
2525 Document, Editor, Theme, View,
2626};
27−use std::{borrow::Cow, path::PathBuf};
27+use std::{borrow::Cow, cmp::min, path::PathBuf};
2828
2929use tui::buffer::Buffer as Surface;
3030
@@ -468,12 +468,18 @@ impl EditorView {
468468 let starting_indent =
469469 (offset.col / tab_width) + config.indent_guides.skip_levels as usize;
470470
471− for i in starting_indent..(indent_level / tab_width) {
471+ // Don't draw indent guides outside of view
472+ let end_indent = min(
473+ indent_level,
474+ // Add tab_width - 1 to round up, since the first visible
475+ // indent might be a bit after offset.col
476+ offset.col + viewport.width as usize + (tab_width - 1),
477+ ) / tab_width;
478+
479+ for i in starting_indent..end_indent {
472480 let x = (viewport.x as usize + (i * tab_width) - offset.col) as u16;
473481 let y = viewport.y + line;
474− if !surface.in_bounds(x, y) {
475− break;
476− }
482+ debug_assert!(surface.in_bounds(x, y));
477483 surface.set_string(x, y, &indent_guide_char, indent_guide_style);
478484 }
479485 };