ui: Make custom rows in ContextMenus use a normal cursor (#15239)

This PR makes custom rows in `ContextMenu`s use a regular cursor instead
of a pointer.

Even though custom rows were marked as not selectable, we would still
pass a click handler to them, causing the `ListItem` to show a pointer
cursor.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-25 20:16:53 -04:00 committed by GitHub
parent 4000b0a02c
commit 95d82f88de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -149,8 +149,7 @@ impl ContextMenu {
} }
pub fn label(mut self, label: impl Into<SharedString>) -> Self { pub fn label(mut self, label: impl Into<SharedString>) -> Self {
let label = label.into(); self.items.push(ContextMenuItem::Label(label.into()));
self.items.push(ContextMenuItem::Label(label));
self self
} }
@ -295,9 +294,9 @@ impl ContextMenu {
impl ContextMenuItem { impl ContextMenuItem {
fn is_selectable(&self) -> bool { fn is_selectable(&self) -> bool {
match self { match self {
ContextMenuItem::Separator => false, ContextMenuItem::Header(_)
ContextMenuItem::Label { .. } => false, | ContextMenuItem::Separator
ContextMenuItem::Header(_) => false, | ContextMenuItem::Label { .. } => false,
ContextMenuItem::Entry { .. } => true, ContextMenuItem::Entry { .. } => true,
ContextMenuItem::CustomEntry { selectable, .. } => *selectable, ContextMenuItem::CustomEntry { selectable, .. } => *selectable,
} }
@ -428,19 +427,19 @@ impl Render for ContextMenu {
} => { } => {
let handler = handler.clone(); let handler = handler.clone();
let menu = cx.view().downgrade(); let menu = cx.view().downgrade();
let selectable = *selectable;
ListItem::new(ix) ListItem::new(ix)
.inset(true) .inset(true)
.selected(if *selectable { .selected(if selectable {
Some(ix) == self.selected_index Some(ix) == self.selected_index
} else { } else {
false false
}) })
.selectable(*selectable) .selectable(selectable)
.on_click({ .when(selectable, |item| {
let context = self.action_context.clone(); item.on_click({
let selectable = *selectable; let context = self.action_context.clone();
move |_, cx| { move |_, cx| {
if selectable {
handler(context.as_ref(), cx); handler(context.as_ref(), cx);
menu.update(cx, |menu, cx| { menu.update(cx, |menu, cx| {
menu.clicked = true; menu.clicked = true;
@ -448,7 +447,7 @@ impl Render for ContextMenu {
}) })
.ok(); .ok();
} }
} })
}) })
.child(entry_render(cx)) .child(entry_render(cx))
.into_any_element() .into_any_element()