From 9d5ae516fd4fed2bbc6f213f6adf93a05f3acd38 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:56:10 -0300 Subject: [PATCH] assistant2: Add keybinding for "Remove All Context" action (#22783) Ensuring all of the assistant 2 actions have keybindings. Release Notes: - N/A --------- Co-authored-by: Agus Zubiaga Co-authored-by: Marshall Bowers --- assets/keymaps/default-macos.json | 4 ++- crates/assistant2/src/assistant.rs | 1 + crates/assistant2/src/context_strip.rs | 27 ++++++++++++------- crates/assistant2/src/inline_prompt_editor.rs | 15 ++++++++--- crates/assistant2/src/message_editor.rs | 8 +++++- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json index 6aa3e2cb087095a2b5916ea259e6df6372127f05..0bc1689ee0db163f59e371d64ae9cbee2ad41d97 100644 --- a/assets/keymaps/default-macos.json +++ b/assets/keymaps/default-macos.json @@ -227,7 +227,8 @@ "cmd-n": "assistant2::NewThread", "cmd-shift-h": "assistant2::OpenHistory", "cmd-shift-m": "assistant2::ToggleModelSelector", - "cmd-shift-a": "assistant2::ToggleContextPicker" + "cmd-shift-a": "assistant2::ToggleContextPicker", + "cmd-alt-e": "assistant2::RemoveAllContext" } }, { @@ -615,6 +616,7 @@ "use_key_equivalents": true, "bindings": { "cmd-shift-a": "assistant2::ToggleContextPicker", + "cmd-alt-e": "assistant2::RemoveAllContext", "ctrl-[": "assistant::CyclePreviousInlineAssist", "ctrl-]": "assistant::CycleNextInlineAssist" } diff --git a/crates/assistant2/src/assistant.rs b/crates/assistant2/src/assistant.rs index 84081528ebf41086f4333f6a0ea9e9fd194d7058..762a9bbcea3eca7e614eb30e391f1dd5d8c370ad 100644 --- a/crates/assistant2/src/assistant.rs +++ b/crates/assistant2/src/assistant.rs @@ -41,6 +41,7 @@ actions!( NewThread, ToggleContextPicker, ToggleModelSelector, + RemoveAllContext, OpenHistory, Chat, CycleNextInlineAssist, diff --git a/crates/assistant2/src/context_strip.rs b/crates/assistant2/src/context_strip.rs index f7c85dc63126afbfbc1785841126833585add0e4..ded54edc82d06d8459d6563318db85a2dd524b22 100644 --- a/crates/assistant2/src/context_strip.rs +++ b/crates/assistant2/src/context_strip.rs @@ -15,7 +15,7 @@ use crate::context_store::ContextStore; use crate::thread::Thread; use crate::thread_store::ThreadStore; use crate::ui::ContextPill; -use crate::{AssistantPanel, ToggleContextPicker}; +use crate::{AssistantPanel, RemoveAllContext, ToggleContextPicker}; pub struct ContextStrip { context_store: Model, @@ -226,14 +226,23 @@ impl Render for ContextStrip { 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(); - }) - }), + .tooltip({ + let focus_handle = focus_handle.clone(); + move |cx| { + Tooltip::for_action_in( + "Remove All Context", + &RemoveAllContext, + &focus_handle, + cx, + ) + } + }) + .on_click(cx.listener({ + let focus_handle = focus_handle.clone(); + move |_this, _event, cx| { + focus_handle.dispatch_action(&RemoveAllContext, cx); + } + })), ) } }) diff --git a/crates/assistant2/src/inline_prompt_editor.rs b/crates/assistant2/src/inline_prompt_editor.rs index 0af6ca2d15e3b220ff550168c81264cc16de18dc..9ab660eb23b9d2d7ad194374a7c624b22877766d 100644 --- a/crates/assistant2/src/inline_prompt_editor.rs +++ b/crates/assistant2/src/inline_prompt_editor.rs @@ -6,7 +6,7 @@ use crate::context_strip::{ContextStrip, ContextStripEvent, SuggestContextKind}; use crate::terminal_codegen::TerminalCodegen; use crate::thread_store::ThreadStore; use crate::{CycleNextInlineAssist, CyclePreviousInlineAssist}; -use crate::{ToggleContextPicker, ToggleModelSelector}; +use crate::{RemoveAllContext, ToggleContextPicker, ToggleModelSelector}; use client::ErrorExt; use collections::VecDeque; use editor::{ @@ -37,6 +37,7 @@ use workspace::Workspace; pub struct PromptEditor { pub editor: View, mode: PromptEditorMode, + context_store: Model, context_strip: View, context_picker_menu_handle: PopoverMenuHandle, model_selector: View, @@ -109,6 +110,7 @@ impl Render for PromptEditor { .on_action(cx.listener(Self::cancel)) .on_action(cx.listener(Self::move_up)) .on_action(cx.listener(Self::move_down)) + .on_action(cx.listener(Self::remove_all_context)) .capture_action(cx.listener(Self::cycle_prev)) .capture_action(cx.listener(Self::cycle_next)) .child( @@ -339,6 +341,11 @@ impl PromptEditor { self.model_selector_menu_handle.toggle(cx); } + pub fn remove_all_context(&mut self, _: &RemoveAllContext, cx: &mut ViewContext) { + self.context_store.update(cx, |store, _cx| store.clear()); + cx.notify(); + } + fn cancel(&mut self, _: &editor::actions::Cancel, cx: &mut ViewContext) { match self.codegen_status(cx) { CodegenStatus::Idle | CodegenStatus::Done | CodegenStatus::Error(_) => { @@ -816,7 +823,7 @@ impl PromptEditor { let context_strip = cx.new_view(|cx| { ContextStrip::new( - context_store, + context_store.clone(), workspace.clone(), thread_store.clone(), prompt_editor.focus_handle(cx), @@ -831,6 +838,7 @@ impl PromptEditor { let mut this: PromptEditor = PromptEditor { editor: prompt_editor.clone(), + context_store, context_strip, context_picker_menu_handle, model_selector: cx.new_view(|cx| { @@ -962,7 +970,7 @@ impl PromptEditor { let context_strip = cx.new_view(|cx| { ContextStrip::new( - context_store, + context_store.clone(), workspace.clone(), thread_store.clone(), prompt_editor.focus_handle(cx), @@ -977,6 +985,7 @@ impl PromptEditor { let mut this = Self { editor: prompt_editor.clone(), + context_store, context_strip, context_picker_menu_handle, model_selector: cx.new_view(|cx| { diff --git a/crates/assistant2/src/message_editor.rs b/crates/assistant2/src/message_editor.rs index 684b5c5df0c098ced990d5f9cba1fe24f39292b2..54a818c7db6824c158d6ea3ea4f6d6289c5d8340 100644 --- a/crates/assistant2/src/message_editor.rs +++ b/crates/assistant2/src/message_editor.rs @@ -23,7 +23,7 @@ use crate::context_store::ContextStore; use crate::context_strip::{ContextStrip, ContextStripEvent, SuggestContextKind}; use crate::thread::{RequestKind, Thread}; use crate::thread_store::ThreadStore; -use crate::{Chat, ToggleContextPicker, ToggleModelSelector}; +use crate::{Chat, RemoveAllContext, ToggleContextPicker, ToggleModelSelector}; pub struct MessageEditor { thread: Model, @@ -116,6 +116,11 @@ impl MessageEditor { self.context_picker_menu_handle.toggle(cx); } + pub fn remove_all_context(&mut self, _: &RemoveAllContext, cx: &mut ViewContext) { + self.context_store.update(cx, |store, _cx| store.clear()); + cx.notify(); + } + fn chat(&mut self, _: &Chat, cx: &mut ViewContext) { self.send_to_model(RequestKind::Chat, cx); } @@ -233,6 +238,7 @@ impl Render for MessageEditor { .on_action(cx.listener(Self::chat)) .on_action(cx.listener(Self::toggle_model_selector)) .on_action(cx.listener(Self::toggle_context_picker)) + .on_action(cx.listener(Self::remove_all_context)) .size_full() .gap_2() .p_2()