editor: Fix incorrect hover popup row clamping (#41645)

Fixes ZED-2TR
Fixes ZED-2TQ
Fixes ZED-2TB
Fixes ZED-2SW
Fixes ZED-2SQ

Release Notes:

- Fixed panic in repainting hover popups

Co-authored by: David <david@zed.dev>
This commit is contained in:
Lukas Wirth
2025-10-31 14:24:23 +00:00
committed by GitHub
parent 1f938c08d2
commit c6d61870e2
2 changed files with 23 additions and 17 deletions
+7 -5
View File
@@ -5114,19 +5114,21 @@ impl EditorElement {
cx, cx,
) )
}); });
let Some((position, hover_popovers)) = hover_popovers else { let Some((popover_position, hover_popovers)) = hover_popovers else {
return; return;
}; };
// This is safe because we check on layout whether the required row is available // This is safe because we check on layout whether the required row is available
let hovered_row_layout = let hovered_row_layout = &line_layouts[popover_position
&line_layouts[position.row().minus(visible_display_row_range.start) as usize]; .row()
.minus(visible_display_row_range.start)
as usize];
// Compute Hovered Point // Compute Hovered Point
let x = hovered_row_layout.x_for_index(position.column() as usize) let x = hovered_row_layout.x_for_index(popover_position.column() as usize)
- Pixels::from(scroll_pixel_position.x); - Pixels::from(scroll_pixel_position.x);
let y = Pixels::from( let y = Pixels::from(
position.row().as_f64() * ScrollPixelOffset::from(line_height) popover_position.row().as_f64() * ScrollPixelOffset::from(line_height)
- scroll_pixel_position.y, - scroll_pixel_position.y,
); );
let hovered_point = content_origin + point(x, y); let hovered_point = content_origin + point(x, y);
+16 -12
View File
@@ -797,9 +797,18 @@ impl HoverState {
}) })
})?; })?;
let mut point = anchor.to_display_point(&snapshot.display_snapshot); let mut point = anchor.to_display_point(&snapshot.display_snapshot);
// Clamp the point within the visible rows in case the popup source spans multiple lines // Clamp the point within the visible rows in case the popup source spans multiple lines
if point.row() < visible_rows.start { if visible_rows.end <= point.row() {
point = crate::movement::up_by_rows(
&snapshot.display_snapshot,
point,
1 + (point.row() - visible_rows.end).0,
text::SelectionGoal::None,
true,
text_layout_details,
)
.0;
} else if point.row() < visible_rows.start {
point = crate::movement::down_by_rows( point = crate::movement::down_by_rows(
&snapshot.display_snapshot, &snapshot.display_snapshot,
point, point,
@@ -809,16 +818,11 @@ impl HoverState {
text_layout_details, text_layout_details,
) )
.0; .0;
} else if visible_rows.end <= point.row() { }
point = crate::movement::up_by_rows(
&snapshot.display_snapshot, if !visible_rows.contains(&point.row()) {
point, log::error!("Hover popover point out of bounds after moving");
(visible_rows.end - point.row()).0, return None;
text::SelectionGoal::None,
true,
text_layout_details,
)
.0;
} }
let mut elements = Vec::new(); let mut elements = Vec::new();