assistant2: Fix inline context picker and handle dismiss (#23081)
The new `ContextMenu`-based `ContextPicker` requires initialization when opened, but we were only doing this for the `ContextStrip` picker, not the inline one. Additionally, because we have a wrapper element around ContextMenu, we need to propagate the `DismissEvent` so that it properly closes when Escape is pressed. Release Notes: - N/A
This commit is contained in:
parent
7c2c409f6d
commit
4054d4a5b7
8 changed files with 42 additions and 17 deletions
|
@ -65,14 +65,15 @@ impl ContextPicker {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn reset_mode(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.mode = ContextPickerMode::Default(self.build(cx));
|
||||
pub fn init(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.mode = ContextPickerMode::Default(self.build_menu(cx));
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn build(&mut self, cx: &mut ViewContext<Self>) -> View<ContextMenu> {
|
||||
fn build_menu(&mut self, cx: &mut ViewContext<Self>) -> View<ContextMenu> {
|
||||
let context_picker = cx.view().clone();
|
||||
|
||||
ContextMenu::build(cx, move |menu, cx| {
|
||||
let menu = ContextMenu::build(cx, move |menu, cx| {
|
||||
let kind_entry = |kind: &'static ContextKind| {
|
||||
let context_picker = context_picker.clone();
|
||||
|
||||
|
@ -90,11 +91,24 @@ impl ContextPicker {
|
|||
.enumerate()
|
||||
.map(|(ix, entry)| self.recent_menu_item(context_picker.clone(), ix, entry));
|
||||
|
||||
menu.when(has_recent, |menu| menu.label("Recent"))
|
||||
let menu = menu
|
||||
.when(has_recent, |menu| menu.label("Recent"))
|
||||
.extend(recent_entries)
|
||||
.when(has_recent, |menu| menu.separator())
|
||||
.extend(ContextKind::all().into_iter().map(kind_entry))
|
||||
.extend(ContextKind::all().into_iter().map(kind_entry));
|
||||
|
||||
match self.confirm_behavior {
|
||||
ConfirmBehavior::KeepOpen => menu.keep_open_on_confirm(),
|
||||
ConfirmBehavior::Close => menu,
|
||||
}
|
||||
});
|
||||
|
||||
cx.subscribe(&menu, move |_, _, _: &DismissEvent, cx| {
|
||||
cx.emit(DismissEvent);
|
||||
})
|
||||
.detach();
|
||||
|
||||
menu
|
||||
}
|
||||
|
||||
fn select_kind(&mut self, kind: ContextKind, cx: &mut ViewContext<Self>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue