editor: Ensure minimap top offset is never NaN
(#31466)
(Late) Follow-up to https://github.com/zed-industries/zed/pull/26893#discussion_r2073427393 The mentioned issue of needed zero-division for scrollbars is now fixed via #30189. However, whilst the linked PR fixed the issue for the layouting of the scrollbar thumb, I sadly did not address the (somewhat rare) case of `document_lines == visible_editor_lines` within the calculation of the minimap top offset. This PR adds coverage for that case and ensures that the `minimap_top_offset` never ends up being `NaN`. Release Notes: - N/A
This commit is contained in:
parent
f8365c5375
commit
24809c4219
1 changed files with 7 additions and 3 deletions
|
@ -9164,9 +9164,13 @@ impl MinimapLayout {
|
|||
visible_minimap_lines: f32,
|
||||
scroll_position: f32,
|
||||
) -> f32 {
|
||||
let scroll_percentage =
|
||||
(scroll_position / (document_lines - visible_editor_lines)).clamp(0., 1.);
|
||||
scroll_percentage * (document_lines - visible_minimap_lines).max(0.)
|
||||
let non_visible_document_lines = (document_lines - visible_editor_lines).max(0.);
|
||||
if non_visible_document_lines == 0. {
|
||||
0.
|
||||
} else {
|
||||
let scroll_percentage = (scroll_position / non_visible_document_lines).clamp(0., 1.);
|
||||
scroll_percentage * (document_lines - visible_minimap_lines).max(0.)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue