diff options
author | A-Walrus | 2022-10-17 11:23:50 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-10-17 15:38:16 +0000 |
commit | 8bbddf90ffda7c37f8a87f71227a185007ddfae0 (patch) | |
tree | 63aba8f868d10ffff5da7add9ec3d28a76afbf79 | |
parent | 1de02a147c1738015aa26dea7c8fd313f3741d8e (diff) |
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.
-rw-r--r-- | helix-term/src/ui/editor.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 4074534b..3cd2130a 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -24,7 +24,7 @@ use helix_view::{ keyboard::{KeyCode, KeyModifiers}, Document, Editor, Theme, View, }; -use std::{borrow::Cow, path::PathBuf}; +use std::{borrow::Cow, cmp::min, path::PathBuf}; use tui::buffer::Buffer as Surface; @@ -468,12 +468,18 @@ impl EditorView { let starting_indent = (offset.col / tab_width) + config.indent_guides.skip_levels as usize; - for i in starting_indent..(indent_level / tab_width) { + // Don't draw indent guides outside of view + let end_indent = min( + indent_level, + // Add tab_width - 1 to round up, since the first visible + // indent might be a bit after offset.col + offset.col + viewport.width as usize + (tab_width - 1), + ) / tab_width; + + for i in starting_indent..end_indent { let x = (viewport.x as usize + (i * tab_width) - offset.col) as u16; let y = viewport.y + line; - if !surface.in_bounds(x, y) { - break; - } + debug_assert!(surface.in_bounds(x, y)); surface.set_string(x, y, &indent_guide_char, indent_guide_style); } }; |