agent: Keyboard navigation improvements (#30274)

- Fix `ctrl-p` not working in the model selector
- Select first entry when opening the context picker

Release Notes:

- Fixed `menu::SelectPrevious` keybindings not working in the agent
panel's model selector.
This commit is contained in:
Cole Miller 2025-05-09 09:52:06 -04:00 committed by GitHub
parent 0abee5668a
commit 9cff5cfe3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 8 deletions

View file

@ -381,6 +381,16 @@ impl ContextPicker {
cx.focus_self(window);
}
pub fn select_first(&mut self, window: &mut Window, cx: &mut Context<Self>) {
match &self.mode {
ContextPickerState::Default(entity) => entity.update(cx, |entity, cx| {
entity.select_first(&Default::default(), window, cx)
}),
// Other variants already select their first entry on open automatically
_ => {}
}
}
fn recent_menu_item(
&self,
context_picker: Entity<ContextPicker>,

View file

@ -420,12 +420,25 @@ impl Render for ContextStrip {
})
.child(
PopoverMenu::new("context-picker")
.menu(move |window, cx| {
context_picker.update(cx, |this, cx| {
this.init(window, cx);
});
.menu({
let context_picker = context_picker.clone();
move |window, cx| {
context_picker.update(cx, |this, cx| {
this.init(window, cx);
});
Some(context_picker.clone())
Some(context_picker.clone())
}
})
.on_open({
let context_picker = context_picker.downgrade();
Rc::new(move |window, cx| {
context_picker
.update(cx, |context_picker, cx| {
context_picker.select_first(window, cx);
})
.ok();
})
})
.trigger_with_tooltip(
IconButton::new("add-context", IconName::Plus)