Skip to content

Commit 8bbddf9

Browse files
A-Walrusarchseer
authored andcommitted
Replace in_bounds with calculation of end_indent
Instead of repeatedly checking if it is in_bounds, calculate the max_indent beforehand and just loop. I added a debug_assert to "prove" that it never tries drawing out of bounds.
1 parent 1de02a1 commit 8bbddf9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

helix-term/src/ui/editor.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2929
use 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
};

0 commit comments

Comments
 (0)