assistant: Fix toggling the model selector via keybind (#16319)

This PR restores the ability to toggle the model selector via a keybind
after it was lost in #15693.

Release Notes:

- Restored the ability to toggle the model selector in the Assistant via
a keybinding (Preview only).
This commit is contained in:
Marshall Bowers 2024-08-15 17:45:25 -04:00 committed by GitHub
parent 776442f3ae
commit f65b2b9a2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 46 deletions

View file

@ -17,7 +17,7 @@ use crate::{
PendingSlashCommandStatus, QuoteSelection, RemoteContextMetadata, ResolvedWorkflowStep, PendingSlashCommandStatus, QuoteSelection, RemoteContextMetadata, ResolvedWorkflowStep,
SavedContextMetadata, Split, ToggleFocus, ToggleModelSelector, WorkflowStepView, SavedContextMetadata, Split, ToggleFocus, ToggleModelSelector, WorkflowStepView,
}; };
use crate::{ContextStoreEvent, ShowConfiguration}; use crate::{ContextStoreEvent, ModelPickerDelegate, ShowConfiguration};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use assistant_slash_command::{SlashCommand, SlashCommandOutputSection}; use assistant_slash_command::{SlashCommand, SlashCommandOutputSection};
use client::{proto, Client, Status}; use client::{proto, Client, Status};
@ -145,7 +145,7 @@ pub struct AssistantPanel {
languages: Arc<LanguageRegistry>, languages: Arc<LanguageRegistry>,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
subscriptions: Vec<Subscription>, subscriptions: Vec<Subscription>,
model_selector_menu_handle: PopoverMenuHandle<ContextMenu>, model_selector_menu_handle: PopoverMenuHandle<Picker<ModelPickerDelegate>>,
model_summary_editor: View<Editor>, model_summary_editor: View<Editor>,
authenticate_provider_task: Option<(LanguageModelProviderId, Task<()>)>, authenticate_provider_task: Option<(LanguageModelProviderId, Task<()>)>,
configuration_subscription: Option<Subscription>, configuration_subscription: Option<Subscription>,
@ -4044,12 +4044,13 @@ pub struct ContextEditorToolbarItem {
workspace: WeakView<Workspace>, workspace: WeakView<Workspace>,
active_context_editor: Option<WeakView<ContextEditor>>, active_context_editor: Option<WeakView<ContextEditor>>,
model_summary_editor: View<Editor>, model_summary_editor: View<Editor>,
model_selector_menu_handle: PopoverMenuHandle<Picker<ModelPickerDelegate>>,
} }
impl ContextEditorToolbarItem { impl ContextEditorToolbarItem {
pub fn new( pub fn new(
workspace: &Workspace, workspace: &Workspace,
_model_selector_menu_handle: PopoverMenuHandle<ContextMenu>, model_selector_menu_handle: PopoverMenuHandle<Picker<ModelPickerDelegate>>,
model_summary_editor: View<Editor>, model_summary_editor: View<Editor>,
) -> Self { ) -> Self {
Self { Self {
@ -4057,6 +4058,7 @@ impl ContextEditorToolbarItem {
workspace: workspace.weak_handle(), workspace: workspace.weak_handle(),
active_context_editor: None, active_context_editor: None,
model_summary_editor, model_summary_editor,
model_selector_menu_handle,
} }
} }
@ -4190,7 +4192,8 @@ impl Render for ContextEditorToolbarItem {
let right_side = h_flex() let right_side = h_flex()
.gap_2() .gap_2()
.child(ModelSelector::new( .child(
ModelSelector::new(
self.fs.clone(), self.fs.clone(),
ButtonLike::new("active-model") ButtonLike::new("active-model")
.style(ButtonStyle::Subtle) .style(ButtonStyle::Subtle)
@ -4232,7 +4235,9 @@ impl Render for ContextEditorToolbarItem {
.tooltip(move |cx| { .tooltip(move |cx| {
Tooltip::for_action("Change Model", &ToggleModelSelector, cx) Tooltip::for_action("Change Model", &ToggleModelSelector, cx)
}), }),
)) )
.with_handle(self.model_selector_menu_handle.clone()),
)
.children(self.render_remaining_tokens(cx)) .children(self.render_remaining_tokens(cx))
.child(self.render_inject_context_menu(cx)); .child(self.render_inject_context_menu(cx));

View file

@ -295,5 +295,6 @@ impl<T: PopoverTrigger> RenderOnce for ModelSelector<T> {
.menu(move |_cx| Some(picker_view.clone())) .menu(move |_cx| Some(picker_view.clone()))
.trigger(self.trigger) .trigger(self.trigger)
.attach(gpui::AnchorCorner::BottomLeft) .attach(gpui::AnchorCorner::BottomLeft)
.when_some(self.handle, |menu, handle| menu.with_handle(handle))
} }
} }