assistant2: Navigate context strip with keyboard (#23128)

Context pills are now focusable and intractable via the keyboard.

- <kbd>←</kbd> and <kbd>→</kbd> move the focus to the previous or next
item (wrapping if necessary)
- <kbd>↓</kbd> and <kbd>↑</kbd> move the focus vertically
- If the cursor is in the first/last row of the assistant/inline editor,
they will move the focus to the strip
- Inside the strip, they will move the focus to the pill horizontally
overlapping the most
- If already in the first/last row of the strip, they will move to the
first/last pill (like in editors)
- If the first/last pill is focused, they will move the focus back to
the editor
- <kbd>⌫</kbd>  removes the focused pill (unless it's the suggested one)
- <kbd>⏎</kbd> accepts the suggested pill if focused
  


https://github.com/user-attachments/assets/040bc71c-a3ae-4961-9886-2d5c3d290a73



Release Notes:

- N/A
This commit is contained in:
Agus Zubiaga 2025-01-14 13:45:11 -03:00 committed by GitHub
parent 78fd5b5f02
commit 39ac6e4a75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 405 additions and 70 deletions

View file

@ -415,6 +415,8 @@ impl<T: 'static> PromptEditor<T> {
editor.move_to_end(&Default::default(), cx)
});
}
} else {
cx.focus_view(&self.context_strip);
}
}
@ -738,11 +740,18 @@ impl<T: 'static> PromptEditor<T> {
fn handle_context_strip_event(
&mut self,
_context_strip: View<ContextStrip>,
ContextStripEvent::PickerDismissed: &ContextStripEvent,
event: &ContextStripEvent,
cx: &mut ViewContext<Self>,
) {
let editor_focus_handle = self.editor.focus_handle(cx);
cx.focus(&editor_focus_handle);
match event {
ContextStripEvent::PickerDismissed
| ContextStripEvent::BlurredEmpty
| ContextStripEvent::BlurredUp => {
let editor_focus_handle = self.editor.focus_handle(cx);
cx.focus(&editor_focus_handle);
}
ContextStripEvent::BlurredDown => {}
}
}
}
@ -826,7 +835,6 @@ impl PromptEditor<BufferCodegen> {
context_store.clone(),
workspace.clone(),
thread_store.clone(),
prompt_editor.focus_handle(cx),
context_picker_menu_handle.clone(),
SuggestContextKind::Thread,
cx,
@ -978,7 +986,6 @@ impl PromptEditor<TerminalCodegen> {
context_store.clone(),
workspace.clone(),
thread_store.clone(),
prompt_editor.focus_handle(cx),
context_picker_menu_handle.clone(),
SuggestContextKind::Thread,
cx,