Only draw indent guides within bounds

Better performance, and otherwise very long lines with lots of tabs
will wrap around the u16 and come back on the other side, messing up
the beginning skip_levels.
pull/4334/head
A-Walrus 2 years ago committed by Blaž Hrastnik
parent 2c36e33e0a
commit 1de02a147c

@ -467,16 +467,14 @@ impl EditorView {
let starting_indent = let starting_indent =
(offset.col / tab_width) + config.indent_guides.skip_levels as usize; (offset.col / tab_width) + config.indent_guides.skip_levels as usize;
// TODO: limit to a max indent level too. It doesn't cause visual artifacts but it would avoid some
// extra loops if the code is deeply nested.
for i in starting_indent..(indent_level / tab_width) { for i in starting_indent..(indent_level / tab_width) {
surface.set_string( let x = (viewport.x as usize + (i * tab_width) - offset.col) as u16;
(viewport.x as usize + (i * tab_width) - offset.col) as u16, let y = viewport.y + line;
viewport.y + line, if !surface.in_bounds(x, y) {
&indent_guide_char, break;
indent_guide_style, }
); surface.set_string(x, y, &indent_guide_char, indent_guide_style);
} }
}; };

Loading…
Cancel
Save