Use a handler instead of an action for clicks

This prevents dispatching actions on buttons that were not the target of the click.

Co-Authored-By: Marshall <marshall@zed.dev>
This commit is contained in:
Antonio Scandurra 2023-12-06 19:12:01 +01:00
parent e4884f1d76
commit cc9eff89f5
5 changed files with 48 additions and 40 deletions

View file

@ -724,7 +724,10 @@ impl Render for PanelButtons {
.trigger(
IconButton::new(name, icon)
.selected(is_active_button)
.action(action.boxed_clone())
.on_click({
let action = action.boxed_clone();
move |_, cx| cx.dispatch_action(action.boxed_clone())
})
.tooltip(move |cx| {
Tooltip::for_action(tooltip.clone(), &*action, cx)
}),