Fix hover tooltips appearing after related element is pressed (#24540)

Closes https://github.com/zed-industries/zed/issues/23894

Reworks all trigger declarations from
`.trigger(element.tooltip(tooltip))` into
`.trigger_with_tooltip(element, tooltip)` , with new API disallowing
simultaneous trigger and tooltip display.

All existing `.trigger(` calls were replaced, except 2 not applicable
(in dock.rs and pane.rs), 15 left as ones without tooltips, and 2
unchanged places in `inline_completion_button.rs`, where


0f7bb2e9fd/crates/inline_completion_button/src/inline_completion_button.rs (L311-L319)

`with_animation` does not allow us to simply use the same approach.

Release Notes:

- Fixed hover tooltips appearing after related element is pressed

---------

Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
This commit is contained in:
Kirill Bulatov 2025-02-10 02:16:12 +02:00 committed by GitHub
parent 1a133ab9d8
commit 6f7f0f30e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 218 additions and 180 deletions

View file

@ -3,8 +3,8 @@
use std::{cell::RefCell, rc::Rc};
use gpui::{
anchored, deferred, div, point, prelude::FluentBuilder, px, size, AnyElement, App, Bounds,
Corner, DismissEvent, DispatchPhase, Element, ElementId, Entity, Focusable as _,
anchored, deferred, div, point, prelude::FluentBuilder, px, size, AnyElement, AnyView, App,
Bounds, Corner, DismissEvent, DispatchPhase, Element, ElementId, Entity, Focusable as _,
GlobalElementId, HitboxId, InteractiveElement, IntoElement, LayoutId, Length, ManagedView,
MouseDownEvent, ParentElement, Pixels, Point, Style, Window,
};
@ -178,6 +178,28 @@ impl<M: ManagedView> PopoverMenu<M> {
self
}
pub fn trigger_with_tooltip<T: PopoverTrigger + ButtonCommon>(
mut self,
t: T,
tooltip_builder: impl Fn(&mut Window, &mut App) -> AnyView + 'static,
) -> Self {
let on_open = self.on_open.clone();
self.child_builder = Some(Box::new(move |menu, builder| {
let open = menu.borrow().is_some();
t.toggle_state(open)
.when_some(builder, |el, builder| {
el.on_click(move |_, window, cx| {
show_menu(&builder, &menu, on_open.clone(), window, cx)
})
.when(!open, |t| {
t.tooltip(move |window, cx| tooltip_builder(window, cx))
})
})
.into_any_element()
}));
self
}
/// anchor defines which corner of the menu to anchor to the attachment point
/// (by default the cursor position, but see attach)
pub fn anchor(mut self, anchor: Corner) -> Self {