From 56b425fcedc32a7616ab6b92379321f0d6f774e8 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:54:31 -0300 Subject: [PATCH] assistant2: Show the popover keybinding when context is empty (#22452) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR makes it so we always show the "Add Context {keybinding}" text when there's no context pills attached. Also, while we haven't fully implemented the mention system (triggered by typing `@`), we removed the instruction on the message editor placeholder. Once that's fully in place, we should return with it! Screenshot 2024-12-27 at 1 35 56 PM Release Notes: - N/A --------- Co-authored-by: Agus Zubiaga --- crates/assistant2/src/context_strip.rs | 54 ++++++++++++++++++------- crates/assistant2/src/message_editor.rs | 2 +- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/crates/assistant2/src/context_strip.rs b/crates/assistant2/src/context_strip.rs index efcb9862cc92bae64de24ecada56db78ce3d0b5b..7d7bda8b3570f322d1d42e363b2c708a6f634ec4 100644 --- a/crates/assistant2/src/context_strip.rs +++ b/crates/assistant2/src/context_strip.rs @@ -9,6 +9,7 @@ use crate::context_store::ContextStore; use crate::thread_store::ThreadStore; use crate::ui::ContextPill; use crate::ToggleContextPicker; +use settings::Settings; pub struct ContextStrip { context_store: Model, @@ -45,7 +46,7 @@ impl ContextStrip { impl Render for ContextStrip { fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { - let context = self.context_store.read(cx).context(); + let context = self.context_store.read(cx).context().clone(); let context_picker = self.context_picker.clone(); let focus_handle = self.focus_handle.clone(); @@ -76,6 +77,29 @@ impl Render for ContextStrip { }) .with_handle(self.context_picker_menu_handle.clone()), ) + .when(context.is_empty(), { + |parent| { + parent.child( + h_flex() + .id("no-content-info") + .ml_1p5() + .gap_2() + .font(theme::ThemeSettings::get_global(cx).buffer_font.clone()) + .text_size(TextSize::Small.rems(cx)) + .text_color(cx.theme().colors().text_muted) + .child("Add Context") + .children( + ui::KeyBinding::for_action_in( + &ToggleContextPicker, + &self.focus_handle, + cx, + ) + .map(|binding| binding.into_any_element()), + ) + .opacity(0.5), + ) + } + }) .children(context.iter().map(|context| { ContextPill::new(context.clone()).on_remove({ let context = context.clone(); @@ -88,19 +112,21 @@ impl Render for ContextStrip { })) }) })) - .when(!context.is_empty(), |parent| { - parent.child( - IconButton::new("remove-all-context", IconName::Eraser) - .icon_size(IconSize::Small) - .tooltip(move |cx| Tooltip::text("Remove All Context", cx)) - .on_click({ - let context_store = self.context_store.clone(); - cx.listener(move |_this, _event, cx| { - context_store.update(cx, |this, _cx| this.clear()); - cx.notify(); - }) - }), - ) + .when(!context.is_empty(), { + move |parent| { + parent.child( + IconButton::new("remove-all-context", IconName::Eraser) + .icon_size(IconSize::Small) + .tooltip(move |cx| Tooltip::text("Remove All Context", cx)) + .on_click({ + let context_store = self.context_store.clone(); + cx.listener(move |_this, _event, cx| { + context_store.update(cx, |this, _cx| this.clear()); + cx.notify(); + }) + }), + ) + } }) } } diff --git a/crates/assistant2/src/message_editor.rs b/crates/assistant2/src/message_editor.rs index 2b8fcd8c0d2aa423fa5a75dc32d9d6af00311976..3f31552e463130d0f680c02822bdca55145401bb 100644 --- a/crates/assistant2/src/message_editor.rs +++ b/crates/assistant2/src/message_editor.rs @@ -54,7 +54,7 @@ impl MessageEditor { let editor = cx.new_view(|cx| { let mut editor = Editor::auto_height(10, cx); - editor.set_placeholder_text("Ask anything, @ to add context", cx); + editor.set_placeholder_text("Ask anything…", cx); editor.set_show_indent_guides(false, cx); editor