menu: Fix submenu item selection when multiple submenus exist (#1342)
Before: https://github.com/user-attachments/assets/8653953e-4e9d-49e6-946a-1696ea6abee0 After: https://github.com/user-attachments/assets/f5bfbf19-69e1-4e64-81c1-072c61e8a8f7 --------- Co-authored-by: Jason Lee <huacnlee@gmail.com>
This commit is contained in:
parent
7a8be9a628
commit
9d01ac26bc
2 changed files with 29 additions and 25 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, px, Action, App, AppContext, Context, Corner, Entity, FocusHandle, Focusable,
|
Action, App, AppContext, Context, Corner, Entity, FocusHandle, Focusable, InteractiveElement,
|
||||||
InteractiveElement, IntoElement, KeyBinding, ParentElement as _, Render, SharedString,
|
IntoElement, KeyBinding, ParentElement as _, Render, SharedString, Styled as _, Window,
|
||||||
Styled as _, Window,
|
actions, div, px,
|
||||||
};
|
};
|
||||||
use gpui_component::{
|
use gpui_component::{
|
||||||
button::Button, context_menu::ContextMenuExt, h_flex, popup_menu::PopupMenuExt as _, v_flex,
|
ActiveTheme as _, IconName, button::Button, context_menu::ContextMenuExt, h_flex,
|
||||||
ActiveTheme as _, IconName,
|
popup_menu::PopupMenuExt as _, v_flex,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
|
@ -178,7 +178,7 @@ impl Render for MenuStory {
|
||||||
.separator()
|
.separator()
|
||||||
.submenu("Links", window, cx, |menu, _, _| {
|
.submenu("Links", window, cx, |menu, _, _| {
|
||||||
menu.link_with_icon(
|
menu.link_with_icon(
|
||||||
"GitHub Repository",
|
"GPUI Component",
|
||||||
IconName::GitHub,
|
IconName::GitHub,
|
||||||
"https://github.com/longbridge/gpui-component",
|
"https://github.com/longbridge/gpui-component",
|
||||||
)
|
)
|
||||||
|
|
@ -186,6 +186,11 @@ impl Render for MenuStory {
|
||||||
.link("GPUI", "https://gpui.rs")
|
.link("GPUI", "https://gpui.rs")
|
||||||
.link("Zed", "https://zed.dev")
|
.link("Zed", "https://zed.dev")
|
||||||
})
|
})
|
||||||
|
.separator()
|
||||||
|
.submenu("Other Links", window, cx, |menu, _, _| {
|
||||||
|
menu.link("Crates", "https://crates.io")
|
||||||
|
.link("Rust Docs", "https://docs.rs")
|
||||||
|
})
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.child(self.message.clone()),
|
.child(self.message.clone()),
|
||||||
|
|
|
||||||
|
|
@ -953,25 +953,24 @@ impl PopupMenu {
|
||||||
.child(IconName::ChevronRight),
|
.child(IconName::ChevronRight),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child({
|
.when(selected, |this| {
|
||||||
let (anchor, left) = self.child_menu_anchor(window);
|
this.child({
|
||||||
let is_bottom_pos = matches!(anchor, Corner::BottomLeft | Corner::BottomRight);
|
let (anchor, left) = self.child_menu_anchor(window);
|
||||||
|
let is_bottom_pos =
|
||||||
anchored()
|
matches!(anchor, Corner::BottomLeft | Corner::BottomRight);
|
||||||
.anchor(anchor)
|
anchored()
|
||||||
.child(
|
.anchor(anchor)
|
||||||
div()
|
.child(
|
||||||
.id("submenu")
|
div()
|
||||||
.group(&group_name)
|
.id("submenu")
|
||||||
.when(!selected, |this| this.invisible())
|
.occlude()
|
||||||
.group_hover(&group_name, |this| this.visible())
|
.when(is_bottom_pos, |this| this.bottom_0())
|
||||||
.occlude()
|
.when(!is_bottom_pos, |this| this.top_neg_1())
|
||||||
.when(is_bottom_pos, |this| this.bottom_0())
|
.left(left)
|
||||||
.when(!is_bottom_pos, |this| this.top_neg_1())
|
.child(menu.clone()),
|
||||||
.left(left)
|
)
|
||||||
.child(menu.clone()),
|
.snap_to_window_with_margin(Edges::all(EDGE_PADDING))
|
||||||
)
|
})
|
||||||
.snap_to_window_with_margin(Edges::all(EDGE_PADDING))
|
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue