Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when drawing at the edge of the screen. #11737

Merged
merged 1 commit into from
Sep 22, 2024

Conversation

rhogenson
Copy link
Contributor

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.

@the-mikedavis the-mikedavis added the A-helix-term Area: Helix term improvements label Sep 21, 2024
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this happens to fix the issue but it's only "accidentally" right.

The order of this condition was never supposed to matter. cut_of_start != 0 is only true if the grapheme starts before the left edge of the view and in that case in_bounds should be false (the grapheme is not in bounds).

column_in_bounds(column) should be changed to take the widht into account:

pub fn columns_in_bounds(&self, colum: usize, width: usize) -> bool {
    self.offset.col <= colum && column + width <= self.offset.col + self.viewport.width as usize
}

When pressing tab at the edge of the screen, Helix panics in debug mode
subtracting position.col - self.offset.col.

To correctly account for graphemes that are partially visible,
column_in_bounds takes a width and returns whether the whole range is
in bounds.
@rhogenson
Copy link
Contributor Author

Sounds good. Updated.

@archseer archseer merged commit 73deaba into helix-editor:master Sep 22, 2024
6 checks passed
@rhogenson rhogenson deleted the tabs branch September 25, 2024 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants