This commit is contained in:
0xshadow 2025-08-26 22:59:21 +03:00 committed by GitHub
commit 594735fcc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 59 additions and 39 deletions

View file

@ -2410,6 +2410,10 @@ impl Editor {
.is_some_and(|menu| menu.context_menu.focus_handle(cx).is_focused(window))
}
pub fn has_mouse_context_menu(&self) -> bool {
self.mouse_context_menu.is_some()
}
pub fn is_range_selected(&mut self, range: &Range<Anchor>, cx: &mut Context<Self>) -> bool {
if self
.selections
@ -6691,7 +6695,7 @@ impl Editor {
}
}
fn hide_blame_popover(&mut self, cx: &mut Context<Self>) {
pub fn hide_blame_popover(&mut self, cx: &mut Context<Self>) {
self.inline_blame_popover_show_task.take();
if let Some(state) = &mut self.inline_blame_popover {
let hide_task = cx.spawn(async move |editor, cx| {

View file

@ -1164,10 +1164,11 @@ impl EditorElement {
.inline_blame_popover
.as_ref()
.is_some_and(|state| state.keyboard_grace);
let has_context_menu = editor.mouse_context_menu.is_some();
if mouse_over_inline_blame || mouse_over_popover {
if (mouse_over_inline_blame || mouse_over_popover) && !has_context_menu {
editor.show_blame_popover(blame_entry, event.position, false, cx);
} else if !keyboard_grace {
} else if !keyboard_grace || has_context_menu {
editor.hide_blame_popover(cx);
}
} else {
@ -2532,32 +2533,38 @@ impl EditorElement {
});
if let Some(mut element) = maybe_element {
let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);
let overall_height = size.height + HOVER_POPOVER_GAP;
let popover_origin = if target_point.y > overall_height {
point(target_point.x, target_point.y - size.height)
} else {
point(
target_point.x,
target_point.y + line_height + HOVER_POPOVER_GAP,
)
};
let has_mouse_context_menu = self
.editor
.read_with(cx, |editor, _| editor.mouse_context_menu.is_some());
let horizontal_offset = (text_hitbox.top_right().x
- POPOVER_RIGHT_OFFSET
- (popover_origin.x + size.width))
.min(Pixels::ZERO);
if !has_mouse_context_menu {
let size = element.layout_as_root(AvailableSpace::min_size(), window, cx);
let overall_height = size.height + HOVER_POPOVER_GAP;
let popover_origin = if target_point.y > overall_height {
point(target_point.x, target_point.y - size.height)
} else {
point(
target_point.x,
target_point.y + line_height + HOVER_POPOVER_GAP,
)
};
let origin = point(popover_origin.x + horizontal_offset, popover_origin.y);
let popover_bounds = Bounds::new(origin, size);
let horizontal_offset = (text_hitbox.top_right().x
- POPOVER_RIGHT_OFFSET
- (popover_origin.x + size.width))
.min(Pixels::ZERO);
self.editor.update(cx, |editor, _| {
if let Some(state) = &mut editor.inline_blame_popover {
state.popover_bounds = Some(popover_bounds);
}
});
let origin = point(popover_origin.x + horizontal_offset, popover_origin.y);
let popover_bounds = Bounds::new(origin, size);
window.defer_draw(element, origin, 2);
self.editor.update(cx, |editor, _| {
if let Some(state) = &mut editor.inline_blame_popover {
state.popover_bounds = Some(popover_bounds);
}
});
window.defer_draw(element, origin, 2);
}
}
}
@ -4790,7 +4797,7 @@ impl EditorElement {
.anchor(Corner::TopLeft)
.snap_to_window_with_margin(px(8.)),
)
.with_priority(1)
.with_priority(3)
.into_any(),
)
})?;

View file

@ -46,6 +46,9 @@ impl BlameRenderer for GitBlameRenderer {
let author_name = blame_entry.author.as_deref().unwrap_or("<no name>");
let name = util::truncate_and_trailoff(author_name, GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED);
let editor_for_mouse_down = editor.clone();
let editor_for_tooltip = editor;
Some(
h_flex()
.w_full()
@ -73,7 +76,7 @@ impl BlameRenderer for GitBlameRenderer {
deploy_blame_entry_context_menu(
&blame_entry,
details.as_ref(),
editor.clone(),
editor_for_mouse_down.clone(),
event.position,
window,
cx,
@ -99,18 +102,23 @@ impl BlameRenderer for GitBlameRenderer {
)
}
})
.hoverable_tooltip(move |_window, cx| {
cx.new(|cx| {
CommitTooltip::blame_entry(
&blame_entry,
details.clone(),
repository.clone(),
workspace.clone(),
cx,
)
})
.into()
})
.when(
!editor_for_tooltip.read(cx).has_mouse_context_menu(),
|el| {
el.hoverable_tooltip(move |_window, cx| {
cx.new(|cx| {
CommitTooltip::blame_entry(
&blame_entry,
details.clone(),
repository.clone(),
workspace.clone(),
cx,
)
})
.into()
})
},
)
.into_any(),
)
}
@ -409,6 +417,7 @@ fn deploy_blame_entry_context_menu(
});
editor.update(cx, move |editor, cx| {
editor.hide_blame_popover(cx);
editor.deploy_mouse_context_menu(position, context_menu, window, cx);
cx.notify();
});