Get actions + focus working on picker, now that it's a view

Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-11-07 13:48:32 -08:00
parent 36d9633f6f
commit ea603401e2
3 changed files with 18 additions and 14 deletions

View file

@ -1,7 +1,8 @@
use editor::Editor;
use gpui::{
div, uniform_list, Component, Div, ParentElement, Render, StatelessInteractive, Styled,
UniformListScrollHandle, View, ViewContext, VisualContext,
div, uniform_list, Component, Div, FocusEnabled, ParentElement, Render, StatefulInteractivity,
StatelessInteractive, Styled, UniformListScrollHandle, View, ViewContext, VisualContext,
WindowContext,
};
use std::cmp;
@ -41,6 +42,10 @@ impl<D: PickerDelegate> Picker<D> {
}
}
pub fn focus(&self, cx: &mut WindowContext) {
self.editor.update(cx, |editor, cx| editor.focus(cx));
}
fn select_next(&mut self, _: &menu::SelectNext, cx: &mut ViewContext<Self>) {
let count = self.delegate.match_count();
if count > 0 {
@ -91,12 +96,14 @@ impl<D: PickerDelegate> Picker<D> {
}
impl<D: PickerDelegate> Render for Picker<D> {
type Element = Div<Self>;
type Element = Div<Self, StatefulInteractivity<Self>, FocusEnabled<Self>>;
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
div()
.size_full()
.context("picker")
.id("picker-container")
.focusable()
.size_full()
.on_action(Self::select_next)
.on_action(Self::select_prev)
.on_action(Self::select_first)