From a11ebe01fffb00067936f88d6ee8b891225e30d5 Mon Sep 17 00:00:00 2001 From: ethan Date: Fri, 23 Feb 2024 11:38:20 -0700 Subject: [PATCH] Fix Flashing Hover Popover (#8238) Release Notes: - Use an inclusive range for local range containment check to match LSP behavior & fix popover flashing while the cursor moves over the last character of a symbol. https://github.com/zed-industries/zed/assets/17223924/6c3ddc9c-04fb-4414-812f-025ede5ecaf7 --- crates/editor/src/element.rs | 1 + crates/editor/src/hover_popover.rs | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index cdcc8ed1cd7a7859caa9f58bdae04e5be1befd08..099c52d7fd35d4041878a5cc9cd7fe657b61bc7b 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -894,6 +894,7 @@ impl EditorElement { cx: &mut ElementContext, ) { let start_row = layout.visible_display_row_range.start; + // Offset the content_bounds from the text_bounds by the gutter margin (which is roughly half a character wide) to make hit testing work more like how we want. let content_origin = text_bounds.origin + point(layout.gutter_dimensions.margin, Pixels::ZERO); let line_end_overshoot = 0.15 * layout.position_map.line_height; diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index 8bed85305a5d1678b6188e0e4531658ed949c574..fb65e35be73f2d6416458163bcec8901964579db 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -199,9 +199,10 @@ fn show_hover( if symbol_range .as_text_range() .map(|range| { - range - .to_offset(&snapshot.buffer_snapshot) - .contains(&multibuffer_offset) + let hover_range = range.to_offset(&snapshot.buffer_snapshot); + // LSP returns a hover result for the end index of ranges that should be hovered, so we need to + // use an inclusive range here to check if we should dismiss the popover + (hover_range.start..=hover_range.end).contains(&multibuffer_offset) }) .unwrap_or(false) {