assistant: Fix edge case where "Open new context" button would do nothing (#16452)

Co-Authored-by: Thorsten <thorsten@zed.dev>

Release Notes:

- N/A

Co-authored-by: Thorsten <thorsten@zed.dev>
This commit is contained in:
Bennet Bo Fenner 2024-08-19 11:07:04 +02:00 committed by GitHub
parent 8a320668ed
commit 14fa4abce4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -543,19 +543,18 @@ impl AssistantPanel {
cx.emit(AssistantPanelEvent::ContextEdited); cx.emit(AssistantPanelEvent::ContextEdited);
true true
} }
pane::Event::RemovedItem { .. } => {
pane::Event::RemoveItem { idx } => { let has_configuration_view = self
if self
.pane .pane
.read(cx) .read(cx)
.item_for_index(*idx) .items_of_type::<ConfigurationView>()
.map_or(false, |item| item.downcast::<ConfigurationView>().is_some()) .next()
{ .is_some();
if !has_configuration_view {
self.configuration_subscription = None; self.configuration_subscription = None;
} }
false
}
pane::Event::RemovedItem { .. } => {
cx.emit(AssistantPanelEvent::ContextEdited); cx.emit(AssistantPanelEvent::ContextEdited);
true true
} }
@ -4437,6 +4436,7 @@ impl ConfigurationView {
provider: &Arc<dyn LanguageModelProvider>, provider: &Arc<dyn LanguageModelProvider>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Div { ) -> Div {
let provider_id = provider.id().0.clone();
let provider_name = provider.name().0.clone(); let provider_name = provider.name().0.clone();
let configuration_view = self.configuration_views.get(&provider.id()).cloned(); let configuration_view = self.configuration_views.get(&provider.id()).cloned();
@ -4458,12 +4458,15 @@ impl ConfigurationView {
.when(provider.is_authenticated(cx), move |this| { .when(provider.is_authenticated(cx), move |this| {
this.child( this.child(
h_flex().justify_end().child( h_flex().justify_end().child(
Button::new("new-context", "Open new context") Button::new(
.icon_position(IconPosition::Start) SharedString::from(format!("new-context-{provider_id}")),
.icon(IconName::Plus) "Open new context",
.style(ButtonStyle::Filled) )
.layer(ElevationIndex::ModalSurface) .icon_position(IconPosition::Start)
.on_click(open_new_context), .icon(IconName::Plus)
.style(ButtonStyle::Filled)
.layer(ElevationIndex::ModalSurface)
.on_click(open_new_context),
), ),
) )
}), }),