-
Notifications
You must be signed in to change notification settings - Fork 4.2k
editor: Ensure scrollbar thumb is not layouted when content size is smaller than viewport #30189
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
editor: Ensure scrollbar thumb is not layouted when content size is smaller than viewport #30189
Conversation
…maller than viewport
This ensures we do not change the cursor style if we insert a hitbox but do not end up showing a thumb at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let me know whether we want to have this in this PR or whether I shall create a seperate one.
That was +1/-1 change IIRC, so why not, this PR is not as huge as the original one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice follow-up, thank you.
…maller than viewport (zed-industries#30189) As discussed and explained in zed-industries#26893 (comment) This PR fixes an issue where we would have zero-divisions during scrollbar layouting for small files. This happened due to the fact that for small files, https://github.com/zed-industries/zed/blob/9c1b2afa492755a1e8cb0a77f929845941c97cdc/crates/editor/src/element.rs#L8562-L8563 would be `NaN`, since `(total_text_units - text_units_per_page).max(0.)` would return `0.`, which we would divide by. However, this was neccessary to be in place, as this prevented the scroll thumb from being rendered for small files: Due to this being `NaN`, the thumb origin would be `Pixels(NaN)`, which prevented the rendering of the scrollbar thumb. This PR fixes this behavior by accounting for this scenario and changing the thumb bounds to be an `Option<Bounds<Pixels>>` instead. This furthermore has the advantage that we have to compute the thumb only once and storing it in the layout, which was previously not possible. Most notably, this enables scrollbar markers to show for smaller files: https://github.com/user-attachments/assets/9fa5d240-8795-4fae-9933-aed144df4f5e Currently, no markers are shown due to the fact that `Pixels(NaN)` is set as the origin point. Also, I changed that the cursor style will only be changed on the scrollbar hitbox when we will actually show a thumb. This way, for small files (where viewport > content size) the cursor will not change when a user hovers with their mouse over the scrollbars hitbox. Theoretically, I could also include the change mentioned in zed-industries#26893 (comment) here. Given the introduction of the minimap as well as zed-industries#29316 and the cursor style taken care of here, removing the guard would not change anything and creates the possibility to soon introduce scrollbars for auto height editors. Please let me know whether we want to have this in this PR or whether I shall create a seperate one. Release Notes: - Enabled scrollbar marker rendering for small files.
As discussed and explained in #26893 (comment)
This PR fixes an issue where we would have zero-divisions during scrollbar layouting for small files.
This happened due to the fact that for small files,
zed/crates/editor/src/element.rs
Lines 8562 to 8563 in 9c1b2af
would be
NaN
, since(total_text_units - text_units_per_page).max(0.)
would return0.
, which we would divide by.However, this was neccessary to be in place, as this prevented the scroll thumb from being rendered for small files: Due to this being
NaN
, the thumb origin would bePixels(NaN)
, which prevented the rendering of the scrollbar thumb.This PR fixes this behavior by accounting for this scenario and changing the thumb bounds to be an
Option<Bounds<Pixels>>
instead. This furthermore has the advantage that we have to compute the thumb only once and storing it in the layout, which was previously not possible.Most notably, this enables scrollbar markers to show for smaller files:
scrollbar_small_files.mov
Currently, no markers are shown due to the fact that
Pixels(NaN)
is set as the origin point.Also, I changed that the cursor style will only be changed on the scrollbar hitbox when we will actually show a thumb. This way, for small files (where viewport > content size) the cursor will not change when a user hovers with their mouse over the scrollbars hitbox.
Theoretically, I could also include the change mentioned in #26893 (comment) here. Given the introduction of the minimap as well as #29316 and the cursor style taken care of here, removing the guard would not change anything and creates the possibility to soon introduce scrollbars for auto height editors. Please let me know whether we want to have this in this PR or whether I shall create a seperate one.
Release Notes: