From 24809c4219b66b48b030369775723cdb46151304 Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Tue, 27 May 2025 00:21:19 +0200 Subject: [PATCH] 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 --- crates/editor/src/element.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index c3ec3a052fdc621f819e17993c2ffcccd1a437ce..2a304dafe4e914e4d727ebcd8f207d0bce958ff9 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -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.) + } } }