assistant2: Add `ChatMode` action (#23243)

Danilo Leal and Agus Zubiaga created

This PR makes the assistant 2 panel switch work with the keyboard via
the `cmd-e` keybinding.

Release Notes:

- N/A

---------

Co-authored-by: Agus Zubiaga <hi@aguz.me>

Change summary

assets/keymaps/default-linux.json       |  1 +
assets/keymaps/default-macos.json       |  1 +
crates/assistant2/src/assistant.rs      |  1 +
crates/assistant2/src/message_editor.rs | 15 +++++++++++++--
4 files changed, 16 insertions(+), 2 deletions(-)

Detailed changes

assets/keymaps/default-linux.json 🔗

@@ -574,6 +574,7 @@
       "ctrl-shift-h": "assistant2::OpenHistory",
       "ctrl-alt-/": "assistant2::ToggleModelSelector",
       "ctrl-shift-a": "assistant2::ToggleContextPicker",
+      "ctrl-e": "assistant2::ChatMode",
       "ctrl-alt-e": "assistant2::RemoveAllContext"
     }
   },

assets/keymaps/default-macos.json 🔗

@@ -229,6 +229,7 @@
       "cmd-shift-h": "assistant2::OpenHistory",
       "cmd-alt-/": "assistant2::ToggleModelSelector",
       "cmd-shift-a": "assistant2::ToggleContextPicker",
+      "cmd-e": "assistant2::ChatMode",
       "cmd-alt-e": "assistant2::RemoveAllContext"
     }
   },

crates/assistant2/src/message_editor.rs 🔗

@@ -23,7 +23,7 @@ use crate::context_store::{refresh_context_store_text, ContextStore};
 use crate::context_strip::{ContextStrip, ContextStripEvent, SuggestContextKind};
 use crate::thread::{RequestKind, Thread};
 use crate::thread_store::ThreadStore;
-use crate::{Chat, RemoveAllContext, ToggleContextPicker, ToggleModelSelector};
+use crate::{Chat, ChatMode, RemoveAllContext, ToggleContextPicker, ToggleModelSelector};
 
 pub struct MessageEditor {
     thread: Model<Thread>,
@@ -116,6 +116,11 @@ impl MessageEditor {
         self.model_selector_menu_handle.toggle(cx)
     }
 
+    fn toggle_chat_mode(&mut self, _: &ChatMode, cx: &mut ViewContext<Self>) {
+        self.use_tools = !self.use_tools;
+        cx.notify();
+    }
+
     fn toggle_context_picker(&mut self, _: &ToggleContextPicker, cx: &mut ViewContext<Self>) {
         self.context_picker_menu_handle.toggle(cx);
     }
@@ -264,6 +269,7 @@ impl Render for MessageEditor {
             .on_action(cx.listener(Self::toggle_context_picker))
             .on_action(cx.listener(Self::remove_all_context))
             .on_action(cx.listener(Self::move_up))
+            .on_action(cx.listener(Self::toggle_chat_mode))
             .size_full()
             .gap_2()
             .p_2()
@@ -323,7 +329,12 @@ impl Render for MessageEditor {
                                             ToggleState::Unselected
                                             | ToggleState::Indeterminate => false,
                                         };
-                                    })),
+                                    }))
+                                    .key_binding(KeyBinding::for_action_in(
+                                        &ChatMode,
+                                        &focus_handle,
+                                        cx,
+                                    )),
                             )
                             .child(
                                 h_flex().gap_1().child(self.model_selector.clone()).child(