Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent: Only focus on the context strip if it has items to display (#30379)
Ben Brandt9dabf491f01d
diff --git a/crates/agent/src/context_strip.rs b/crates/agent/src/context_strip.rsindex 8fe1a21d748..f28e61aa829 100644--- a/crates/agent/src/context_strip.rs+++ b/crates/agent/src/context_strip.rs@@ -84,6 +84,12 @@ impl ContextStrip {}}+ /// Whether or not the context strip has items to display+ pub fn has_context_items(&self, cx: &App) -> bool {+ self.context_store.read(cx).context().next().is_some()+ || self.suggested_context(cx).is_some()+ }+fn added_contexts(&self, cx: &App) -> Vec<AddedContext> {if let Some(workspace) = self.workspace.upgrade() {let project = workspace.read(cx).project().read(cx);@@ -104,14 +110,14 @@ impl ContextStrip {}}- fn suggested_context(&self, cx: &Context<Self>) -> Option<SuggestedContext> {+ fn suggested_context(&self, cx: &App) -> Option<SuggestedContext> {match self.suggest_context_kind {SuggestContextKind::File => self.suggested_file(cx),SuggestContextKind::Thread => self.suggested_thread(cx),}}- fn suggested_file(&self, cx: &Context<Self>) -> Option<SuggestedContext> {+ fn suggested_file(&self, cx: &App) -> Option<SuggestedContext> {let workspace = self.workspace.upgrade()?;let active_item = workspace.read(cx).active_item(cx)?;@@ -138,7 +144,7 @@ impl ContextStrip {})}- fn suggested_thread(&self, cx: &Context<Self>) -> Option<SuggestedContext> {+ fn suggested_thread(&self, cx: &App) -> Option<SuggestedContext> {if !self.context_picker.read(cx).allow_threads() {return None;}diff --git a/crates/agent/src/inline_prompt_editor.rs b/crates/agent/src/inline_prompt_editor.rsindex 9ccc2655097..693786ca07b 100644--- a/crates/agent/src/inline_prompt_editor.rs+++ b/crates/agent/src/inline_prompt_editor.rs@@ -451,7 +451,7 @@ impl<T: 'static> PromptEditor<T> {editor.move_to_end(&Default::default(), window, cx)});}- } else {+ } else if self.context_strip.read(cx).has_context_items(cx) {self.context_strip.focus_handle(cx).focus(window);}}diff --git a/crates/agent/src/message_editor.rs b/crates/agent/src/message_editor.rsindex adaaa8e39aa..b5133bc4fb9 100644--- a/crates/agent/src/message_editor.rs+++ b/crates/agent/src/message_editor.rs@@ -401,7 +401,7 @@ impl MessageEditor {fn move_up(&mut self, _: &MoveUp, window: &mut Window, cx: &mut Context<Self>) {if self.context_picker_menu_handle.is_deployed() {cx.propagate();- } else {+ } else if self.context_strip.read(cx).has_context_items(cx) {self.context_strip.focus_handle(cx).focus(window);}}