Skip to content

Commit

Permalink
Fix panic when drawing at the edge of the screen.
Browse files Browse the repository at this point in the history
When pressing tab at the edge of the screen, Helix panics in debug mode
subtracting position.col - self.offset.col.

I don't fully understand the logic here, but if cut_off_start < width,
then self.offset.col - position.col < width (from the definition of
cut_off_start), and so self.position.col + width > self.offset.col,
meaning in_bounds is true and the second condition is currently
unreachable.

I believe these conditions should be reversed so that the logic for
rendering partially visible characters can apply properly.
  • Loading branch information
Rose Hogenson committed Sep 20, 2024
1 parent 9f93de5 commit 47a86dc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions helix-term/src/ui/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,7 @@ impl<'a> TextRenderer<'a> {

let in_bounds = self.column_in_bounds(position.col + width - 1);

if in_bounds {
self.surface.set_string(
self.viewport.x + (position.col - self.offset.col) as u16,
self.viewport.y + position.row as u16,
grapheme,
style,
);
} else if cut_off_start != 0 && cut_off_start < width {
if cut_off_start != 0 && cut_off_start < width {
// partially on screen
let rect = Rect::new(
self.viewport.x,
Expand All @@ -451,6 +444,13 @@ impl<'a> TextRenderer<'a> {
1,
);
self.surface.set_style(rect, style);
} else if in_bounds {
self.surface.set_string(
self.viewport.x + (position.col - self.offset.col) as u16,
self.viewport.y + position.row as u16,
grapheme,
style,
);
}

if *is_in_indent_area && !is_whitespace {
Expand Down

0 comments on commit 47a86dc

Please sign in to comment.