Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

rules_library: Fix hover selecting active rule (#53264)

Danilo Lealec832cade62a
diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs
index 1e529cd53f2..eba5b309619 100644
--- a/crates/picker/src/picker.rs
+++ b/crates/picker/src/picker.rs
@@ -121,6 +121,9 @@ pub trait PickerDelegate: Sized + 'static {
) -> bool {
true
}
+ fn select_on_hover(&self) -> bool {
+ true
+ }
// Allows binding some optional effect to when the selection changes.
fn selected_index_changed(
@@ -788,12 +791,14 @@ impl<D: PickerDelegate> Picker<D> {
this.handle_click(ix, event.modifiers.platform, window, cx)
}),
)
- .on_hover(cx.listener(move |this, hovered: &bool, window, cx| {
- if *hovered {
- this.set_selected_index(ix, None, false, window, cx);
- cx.notify();
- }
- }))
+ .when(self.delegate.select_on_hover(), |this| {
+ this.on_hover(cx.listener(move |this, hovered: &bool, window, cx| {
+ if *hovered {
+ this.set_selected_index(ix, None, false, window, cx);
+ cx.notify();
+ }
+ }))
+ })
.children(self.delegate.render_match(
ix,
ix == self.delegate.selected_index(),
diff --git a/crates/rules_library/src/rules_library.rs b/crates/rules_library/src/rules_library.rs
index 7e5a56f22d4..425f7d2aa3d 100644
--- a/crates/rules_library/src/rules_library.rs
+++ b/crates/rules_library/src/rules_library.rs
@@ -225,6 +225,10 @@ impl PickerDelegate for RulePickerDelegate {
}
}
+ fn select_on_hover(&self) -> bool {
+ false
+ }
+
fn placeholder_text(&self, _window: &mut Window, _cx: &mut App) -> Arc<str> {
"Search…".into()
}