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:
Finn Evers 2025-05-27 00:21:19 +02:00 committed by GitHub
parent f8365c5375
commit 24809c4219
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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.)
}
}
}