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:
Agus Zubiaga
2025-01-13 21:00:20 +00:00
committed by GitHub
parent 7c2c409f6d
commit 4054d4a5b7
8 changed files with 42 additions and 17 deletions
+10 -1
View File
@@ -112,6 +112,7 @@ pub struct ContextMenu {
delayed: bool,
clicked: bool,
_on_blur_subscription: Subscription,
keep_open_on_confirm: bool,
}
impl FocusableView for ContextMenu {
@@ -144,6 +145,7 @@ impl ContextMenu {
delayed: false,
clicked: false,
_on_blur_subscription,
keep_open_on_confirm: true,
},
cx,
)
@@ -304,6 +306,11 @@ impl ContextMenu {
self
}
pub fn keep_open_on_confirm(mut self) -> Self {
self.keep_open_on_confirm = true;
self
}
pub fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
let context = self.action_context.as_ref();
if let Some(
@@ -318,7 +325,9 @@ impl ContextMenu {
(handler)(context, cx)
}
cx.emit(DismissEvent);
if !self.keep_open_on_confirm {
cx.emit(DismissEvent);
}
}
pub fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {