list: Use click events instead of mouse events when confirming (#1427)

Fix the issue where inner list buttons do not respond to clicks.
This commit is contained in:
Floyd Wang 2025-10-24 16:51:37 +08:00 committed by GitHub
parent b740123d4b
commit 21eff06e11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 32 deletions

View file

@ -202,7 +202,6 @@ pub struct Button {
)>,
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut Window, &mut App)>>,
on_hover: Option<Rc<dyn Fn(&bool, &mut Window, &mut App)>>,
pub(crate) stop_propagation: bool,
loading: bool,
loading_icon: Option<Icon>,
@ -238,7 +237,6 @@ impl Button {
tooltip: None,
on_click: None,
on_hover: None,
stop_propagation: true,
loading: false,
compact: false,
outline: false,
@ -334,11 +332,6 @@ impl Button {
self
}
pub fn stop_propagation(mut self, val: bool) -> Self {
self.stop_propagation = val;
self
}
pub fn loading_icon(mut self, icon: impl Into<Icon>) -> Self {
self.loading_icon = Some(icon.into());
self
@ -536,13 +529,7 @@ impl RenderOnce for Button {
window.prevent_default();
})
.when_some(self.on_click.filter(|_| clickable), |this, on_click| {
let stop_propagation = self.stop_propagation;
this.on_click(move |_, _, cx| {
if stop_propagation {
cx.stop_propagation();
}
})
.on_click(move |event, window, cx| {
this.on_click(move |event, window, cx| {
(on_click)(event, window, cx);
})
})

View file

@ -200,7 +200,6 @@ impl RenderOnce for ButtonGroup {
bottom: true,
})
}
.stop_propagation(false)
.when_some(self.size, |this, size| this.with_size(size))
.when_some(self.variant, |this, variant| this.with_variant(variant))
.when(self.compact, |this| this.compact())

View file

@ -18,8 +18,8 @@ use gpui::{
IntoElement, KeyBinding, Length, MouseButton, ParentElement, Render, Styled, Task, Window,
};
use gpui::{
px, size, App, AvailableSpace, Context, Edges, EventEmitter, ListSizingBehavior,
MouseDownEvent, Pixels, ScrollStrategy, Subscription,
px, size, App, AvailableSpace, ClickEvent, Context, Edges, EventEmitter, ListSizingBehavior,
Pixels, ScrollStrategy, SharedString, StatefulInteractiveElement, Subscription,
};
use rust_i18n::t;
use smol::Timer;
@ -422,9 +422,10 @@ where
.mouse_right_clicked_index
.map(|s| s.eq_row(ix))
.unwrap_or(false);
let id = SharedString::from(format!("list-item-{}", ix));
div()
.id("list-item")
.id(id)
.w_full()
.relative()
.children(self.delegate.render_item(ix, window, cx).map(|item| {
@ -432,20 +433,17 @@ where
.secondary_selected(mouse_right_clicked)
}))
.when(self.selectable, |this| {
this.on_mouse_down(
MouseButton::Left,
cx.listener(move |this, ev: &MouseDownEvent, window, cx| {
this.mouse_right_clicked_index = None;
this.selected_index = Some(ix);
this.on_action_confirm(
&Confirm {
secondary: ev.modifiers.secondary(),
},
window,
cx,
);
}),
)
this.on_click(cx.listener(move |this, e: &ClickEvent, window, cx| {
this.mouse_right_clicked_index = None;
this.selected_index = Some(ix);
this.on_action_confirm(
&Confirm {
secondary: e.modifiers().secondary(),
},
window,
cx,
);
}))
.on_mouse_down(
MouseButton::Right,
cx.listener(move |this, _, _, cx| {