From 21eff06e11bd2348716fceb885a3b803c1714489 Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Fri, 24 Oct 2025 16:51:37 +0800 Subject: [PATCH] list: Use click events instead of mouse events when confirming (#1427) Fix the issue where inner list buttons do not respond to clicks. --- crates/ui/src/button/button.rs | 15 +------------ crates/ui/src/button/button_group.rs | 1 - crates/ui/src/list/list.rs | 32 +++++++++++++--------------- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/crates/ui/src/button/button.rs b/crates/ui/src/button/button.rs index 1816ab40..be06164f 100644 --- a/crates/ui/src/button/button.rs +++ b/crates/ui/src/button/button.rs @@ -202,7 +202,6 @@ pub struct Button { )>, on_click: Option>, on_hover: Option>, - pub(crate) stop_propagation: bool, loading: bool, loading_icon: Option, @@ -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) -> 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); }) }) diff --git a/crates/ui/src/button/button_group.rs b/crates/ui/src/button/button_group.rs index ec520436..a4794130 100644 --- a/crates/ui/src/button/button_group.rs +++ b/crates/ui/src/button/button_group.rs @@ -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()) diff --git a/crates/ui/src/list/list.rs b/crates/ui/src/list/list.rs index 50ba6615..423f1d04 100644 --- a/crates/ui/src/list/list.rs +++ b/crates/ui/src/list/list.rs @@ -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| {