Determine whether the gutter was hovered

This commit is contained in:
Antonio Scandurra 2023-11-08 15:30:41 +01:00
parent dfc536b4f5
commit 15d40d6df5
2 changed files with 14 additions and 18 deletions

View file

@ -249,11 +249,6 @@ pub struct UnfoldAt {
pub buffer_row: u32, pub buffer_row: u32,
} }
#[action]
pub struct GutterHover {
pub hovered: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum InlayId { pub enum InlayId {
Suggestion(usize), Suggestion(usize),
@ -8309,15 +8304,12 @@ impl Editor {
} }
} }
// todo!() pub fn set_gutter_hovered(&mut self, hovered: bool, cx: &mut ViewContext<Self>) {
// pub fn gutter_hover( if hovered != self.gutter_hovered {
// &mut self, self.gutter_hovered = hovered;
// GutterHover { hovered }: &GutterHover, cx.notify();
// cx: &mut ViewContext<Self>, }
// ) { }
// self.gutter_hovered = *hovered;
// cx.notify();
// }
pub fn insert_blocks( pub fn insert_blocks(
&mut self, &mut self,

View file

@ -351,6 +351,7 @@ impl EditorElement {
event: &MouseMoveEvent, event: &MouseMoveEvent,
position_map: &PositionMap, position_map: &PositionMap,
text_bounds: Bounds<Pixels>, text_bounds: Bounds<Pixels>,
gutter_bounds: Bounds<Pixels>,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> bool { ) -> bool {
let modifiers = event.modifiers; let modifiers = event.modifiers;
@ -388,9 +389,12 @@ impl EditorElement {
); );
} }
// This will be handled more correctly once https://github.com/zed-industries/zed/issues/1218 is completed let text_hovered = text_bounds.contains_point(&event.position);
let gutter_hovered = gutter_bounds.contains_point(&event.position);
editor.set_gutter_hovered(gutter_hovered, cx);
// Don't trigger hover popover if mouse is hovering over context menu // Don't trigger hover popover if mouse is hovering over context menu
if text_bounds.contains_point(&event.position) { if text_hovered {
let point_for_position = position_map.point_for_position(text_bounds, event.position); let point_for_position = position_map.point_for_position(text_bounds, event.position);
match point_for_position.as_valid() { match point_for_position.as_valid() {
@ -420,7 +424,7 @@ impl EditorElement {
} else { } else {
update_go_to_definition_link(editor, None, modifiers.command, modifiers.shift, cx); update_go_to_definition_link(editor, None, modifiers.command, modifiers.shift, cx);
hover_at(editor, None, cx); hover_at(editor, None, cx);
false gutter_hovered
} }
} }
@ -2349,7 +2353,7 @@ impl EditorElement {
return; return;
} }
if Self::mouse_moved(editor, event, &position_map, text_bounds, cx) { if Self::mouse_moved(editor, event, &position_map, text_bounds, gutter_bounds, cx) {
cx.stop_propagation() cx.stop_propagation()
} }
} }