agent: Only focus on the context strip if it has items to display (#30379)
This commit is contained in:
parent
f2dcc98216
commit
9dabf491f0
3 changed files with 11 additions and 5 deletions
|
@ -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> {
|
fn added_contexts(&self, cx: &App) -> Vec<AddedContext> {
|
||||||
if let Some(workspace) = self.workspace.upgrade() {
|
if let Some(workspace) = self.workspace.upgrade() {
|
||||||
let project = workspace.read(cx).project().read(cx);
|
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 {
|
match self.suggest_context_kind {
|
||||||
SuggestContextKind::File => self.suggested_file(cx),
|
SuggestContextKind::File => self.suggested_file(cx),
|
||||||
SuggestContextKind::Thread => self.suggested_thread(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 workspace = self.workspace.upgrade()?;
|
||||||
let active_item = workspace.read(cx).active_item(cx)?;
|
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() {
|
if !self.context_picker.read(cx).allow_threads() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -451,7 +451,7 @@ impl<T: 'static> PromptEditor<T> {
|
||||||
editor.move_to_end(&Default::default(), window, cx)
|
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);
|
self.context_strip.focus_handle(cx).focus(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -401,7 +401,7 @@ impl MessageEditor {
|
||||||
fn move_up(&mut self, _: &MoveUp, window: &mut Window, cx: &mut Context<Self>) {
|
fn move_up(&mut self, _: &MoveUp, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
if self.context_picker_menu_handle.is_deployed() {
|
if self.context_picker_menu_handle.is_deployed() {
|
||||||
cx.propagate();
|
cx.propagate();
|
||||||
} else {
|
} else if self.context_strip.read(cx).has_context_items(cx) {
|
||||||
self.context_strip.focus_handle(cx).focus(window);
|
self.context_strip.focus_handle(cx).focus(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue