From 911112d94a168b6455268cb34c57f10d3455b175 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 19 Aug 2024 14:47:05 +0200 Subject: [PATCH] assistant: Fix toggling slash command menu from toolbar menu (#16459) Release Notes: - N/A --- crates/assistant/src/assistant.rs | 2 +- crates/assistant/src/assistant_panel.rs | 3 ++- crates/assistant/src/slash_command_picker.rs | 27 +++++++------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/crates/assistant/src/assistant.rs b/crates/assistant/src/assistant.rs index 33f9c2dfb98af0c72002d9e6e73972ddd4570d90..2e7242baf67ac1b3bbf38e6c81ce4c638e01b5db 100644 --- a/crates/assistant/src/assistant.rs +++ b/crates/assistant/src/assistant.rs @@ -9,7 +9,7 @@ mod model_selector; mod prompt_library; mod prompts; mod slash_command; -mod slash_command_picker; +pub(crate) mod slash_command_picker; pub mod slash_command_settings; mod streaming_diff; mod terminal_inline_assistant; diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index fb06618ac10ec2f99df7a3104faf7d7d920663f2..71678366755220a1799698d193ab5f9e96161dfb 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -1718,7 +1718,8 @@ pub struct ContextEditor { assistant_panel: WeakView, error_message: Option, show_accept_terms: bool, - slash_menu_handle: PopoverMenuHandle, + pub(crate) slash_menu_handle: + PopoverMenuHandle>, } const DEFAULT_TAB_TITLE: &str = "New Context"; diff --git a/crates/assistant/src/slash_command_picker.rs b/crates/assistant/src/slash_command_picker.rs index 0675964279aefdf9d8d59df9ef5b1391d574a47c..fb2a0f0a1ed8ac9361e68346ec766098abb9704d 100644 --- a/crates/assistant/src/slash_command_picker.rs +++ b/crates/assistant/src/slash_command_picker.rs @@ -9,17 +9,15 @@ use ui::ListItemSpacing; use gpui::SharedString; use gpui::Task; use picker::{Picker, PickerDelegate}; -use ui::{prelude::*, ListItem, PopoverMenu, PopoverMenuHandle, PopoverTrigger}; +use ui::{prelude::*, ListItem, PopoverMenu, PopoverTrigger}; use crate::assistant_panel::ContextEditor; #[derive(IntoElement)] -pub struct SlashCommandSelector { - handle: Option>>, +pub(super) struct SlashCommandSelector { registry: Arc, active_context_editor: WeakView, trigger: T, - info_text: Option, } #[derive(Clone)] @@ -28,7 +26,7 @@ struct SlashCommandInfo { description: SharedString, } -pub struct SlashCommandDelegate { +pub(crate) struct SlashCommandDelegate { all_commands: Vec, filtered_commands: Vec, active_context_editor: WeakView, @@ -36,29 +34,17 @@ pub struct SlashCommandDelegate { } impl SlashCommandSelector { - pub fn new( + pub(crate) fn new( registry: Arc, active_context_editor: WeakView, trigger: T, ) -> Self { SlashCommandSelector { - handle: None, registry, active_context_editor, trigger, - info_text: None, } } - - pub fn with_handle(mut self, handle: PopoverMenuHandle>) -> Self { - self.handle = Some(handle); - self - } - - pub fn with_info_text(mut self, text: impl Into) -> Self { - self.info_text = Some(text.into()); - self - } } impl PickerDelegate for SlashCommandDelegate { @@ -188,6 +174,10 @@ impl RenderOnce for SlashCommandSelector { picker }); + let handle = self + .active_context_editor + .update(cx, |this, _| this.slash_menu_handle.clone()) + .ok(); PopoverMenu::new("model-switcher") .menu(move |_cx| Some(picker_view.clone())) .trigger(self.trigger) @@ -197,5 +187,6 @@ impl RenderOnce for SlashCommandSelector { x: px(0.0), y: px(-16.0), }) + .when_some(handle, |this, handle| this.with_handle(handle)) } }