assistant: Fix toggling slash command menu from toolbar menu (#16459)
Release Notes: - N/A
This commit is contained in:
parent
e68b2d5ecc
commit
911112d94a
3 changed files with 12 additions and 20 deletions
|
@ -9,7 +9,7 @@ mod model_selector;
|
||||||
mod prompt_library;
|
mod prompt_library;
|
||||||
mod prompts;
|
mod prompts;
|
||||||
mod slash_command;
|
mod slash_command;
|
||||||
mod slash_command_picker;
|
pub(crate) mod slash_command_picker;
|
||||||
pub mod slash_command_settings;
|
pub mod slash_command_settings;
|
||||||
mod streaming_diff;
|
mod streaming_diff;
|
||||||
mod terminal_inline_assistant;
|
mod terminal_inline_assistant;
|
||||||
|
|
|
@ -1718,7 +1718,8 @@ pub struct ContextEditor {
|
||||||
assistant_panel: WeakView<AssistantPanel>,
|
assistant_panel: WeakView<AssistantPanel>,
|
||||||
error_message: Option<SharedString>,
|
error_message: Option<SharedString>,
|
||||||
show_accept_terms: bool,
|
show_accept_terms: bool,
|
||||||
slash_menu_handle: PopoverMenuHandle<ContextMenu>,
|
pub(crate) slash_menu_handle:
|
||||||
|
PopoverMenuHandle<Picker<slash_command_picker::SlashCommandDelegate>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_TAB_TITLE: &str = "New Context";
|
const DEFAULT_TAB_TITLE: &str = "New Context";
|
||||||
|
|
|
@ -9,17 +9,15 @@ use ui::ListItemSpacing;
|
||||||
use gpui::SharedString;
|
use gpui::SharedString;
|
||||||
use gpui::Task;
|
use gpui::Task;
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
use ui::{prelude::*, ListItem, PopoverMenu, PopoverMenuHandle, PopoverTrigger};
|
use ui::{prelude::*, ListItem, PopoverMenu, PopoverTrigger};
|
||||||
|
|
||||||
use crate::assistant_panel::ContextEditor;
|
use crate::assistant_panel::ContextEditor;
|
||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct SlashCommandSelector<T: PopoverTrigger> {
|
pub(super) struct SlashCommandSelector<T: PopoverTrigger> {
|
||||||
handle: Option<PopoverMenuHandle<Picker<SlashCommandDelegate>>>,
|
|
||||||
registry: Arc<SlashCommandRegistry>,
|
registry: Arc<SlashCommandRegistry>,
|
||||||
active_context_editor: WeakView<ContextEditor>,
|
active_context_editor: WeakView<ContextEditor>,
|
||||||
trigger: T,
|
trigger: T,
|
||||||
info_text: Option<SharedString>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -28,7 +26,7 @@ struct SlashCommandInfo {
|
||||||
description: SharedString,
|
description: SharedString,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SlashCommandDelegate {
|
pub(crate) struct SlashCommandDelegate {
|
||||||
all_commands: Vec<SlashCommandInfo>,
|
all_commands: Vec<SlashCommandInfo>,
|
||||||
filtered_commands: Vec<SlashCommandInfo>,
|
filtered_commands: Vec<SlashCommandInfo>,
|
||||||
active_context_editor: WeakView<ContextEditor>,
|
active_context_editor: WeakView<ContextEditor>,
|
||||||
|
@ -36,29 +34,17 @@ pub struct SlashCommandDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: PopoverTrigger> SlashCommandSelector<T> {
|
impl<T: PopoverTrigger> SlashCommandSelector<T> {
|
||||||
pub fn new(
|
pub(crate) fn new(
|
||||||
registry: Arc<SlashCommandRegistry>,
|
registry: Arc<SlashCommandRegistry>,
|
||||||
active_context_editor: WeakView<ContextEditor>,
|
active_context_editor: WeakView<ContextEditor>,
|
||||||
trigger: T,
|
trigger: T,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
SlashCommandSelector {
|
SlashCommandSelector {
|
||||||
handle: None,
|
|
||||||
registry,
|
registry,
|
||||||
active_context_editor,
|
active_context_editor,
|
||||||
trigger,
|
trigger,
|
||||||
info_text: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_handle(mut self, handle: PopoverMenuHandle<Picker<SlashCommandDelegate>>) -> Self {
|
|
||||||
self.handle = Some(handle);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_info_text(mut self, text: impl Into<SharedString>) -> Self {
|
|
||||||
self.info_text = Some(text.into());
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PickerDelegate for SlashCommandDelegate {
|
impl PickerDelegate for SlashCommandDelegate {
|
||||||
|
@ -188,6 +174,10 @@ impl<T: PopoverTrigger> RenderOnce for SlashCommandSelector<T> {
|
||||||
picker
|
picker
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let handle = self
|
||||||
|
.active_context_editor
|
||||||
|
.update(cx, |this, _| this.slash_menu_handle.clone())
|
||||||
|
.ok();
|
||||||
PopoverMenu::new("model-switcher")
|
PopoverMenu::new("model-switcher")
|
||||||
.menu(move |_cx| Some(picker_view.clone()))
|
.menu(move |_cx| Some(picker_view.clone()))
|
||||||
.trigger(self.trigger)
|
.trigger(self.trigger)
|
||||||
|
@ -197,5 +187,6 @@ impl<T: PopoverTrigger> RenderOnce for SlashCommandSelector<T> {
|
||||||
x: px(0.0),
|
x: px(0.0),
|
||||||
y: px(-16.0),
|
y: px(-16.0),
|
||||||
})
|
})
|
||||||
|
.when_some(handle, |this, handle| this.with_handle(handle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue