Get actions + focus working on picker, now that it's a view
Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
co-authored by
Marshall
parent
36d9633f6f
commit
ea603401e2
@@ -9186,7 +9186,7 @@ impl Editor {
|
|||||||
// supports
|
// supports
|
||||||
// }
|
// }
|
||||||
|
|
||||||
fn focus(&self, cx: &mut WindowContext) {
|
pub fn focus(&self, cx: &mut WindowContext) {
|
||||||
cx.focus(&self.focus_handle)
|
cx.focus(&self.focus_handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, uniform_list, Component, Div, ParentElement, Render, StatelessInteractive, Styled,
|
div, uniform_list, Component, Div, FocusEnabled, ParentElement, Render, StatefulInteractivity,
|
||||||
UniformListScrollHandle, View, ViewContext, VisualContext,
|
StatelessInteractive, Styled, UniformListScrollHandle, View, ViewContext, VisualContext,
|
||||||
|
WindowContext,
|
||||||
};
|
};
|
||||||
use std::cmp;
|
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>) {
|
fn select_next(&mut self, _: &menu::SelectNext, cx: &mut ViewContext<Self>) {
|
||||||
let count = self.delegate.match_count();
|
let count = self.delegate.match_count();
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
@@ -91,12 +96,14 @@ impl<D: PickerDelegate> Picker<D> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<D: PickerDelegate> Render for 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 {
|
fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
div()
|
div()
|
||||||
.size_full()
|
|
||||||
.context("picker")
|
.context("picker")
|
||||||
|
.id("picker-container")
|
||||||
|
.focusable()
|
||||||
|
.size_full()
|
||||||
.on_action(Self::select_next)
|
.on_action(Self::select_next)
|
||||||
.on_action(Self::select_prev)
|
.on_action(Self::select_prev)
|
||||||
.on_action(Self::select_first)
|
.on_action(Self::select_first)
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
use gpui::{
|
use gpui::{
|
||||||
div, Component, Div, FocusHandle, KeyBinding, ParentElement, Render, SharedString,
|
div, Component, Div, KeyBinding, ParentElement, Render, SharedString, StatelessInteractive,
|
||||||
StatelessInteractive, Styled, View, VisualContext, WindowContext,
|
Styled, View, VisualContext, WindowContext,
|
||||||
};
|
};
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
use theme2::ActiveTheme;
|
use theme2::ActiveTheme;
|
||||||
|
|
||||||
pub struct PickerStory {
|
pub struct PickerStory {
|
||||||
picker: View<Picker<Delegate>>,
|
picker: View<Picker<Delegate>>,
|
||||||
focus_handle: FocusHandle,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Delegate {
|
struct Delegate {
|
||||||
@@ -86,13 +85,9 @@ impl PickerStory {
|
|||||||
KeyBinding::new("ctrl-c", menu::Cancel, Some("picker")),
|
KeyBinding::new("ctrl-c", menu::Cancel, Some("picker")),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let focus_handle = cx.focus_handle();
|
|
||||||
cx.focus(&focus_handle);
|
|
||||||
|
|
||||||
PickerStory {
|
PickerStory {
|
||||||
focus_handle,
|
|
||||||
picker: cx.build_view(|cx| {
|
picker: cx.build_view(|cx| {
|
||||||
Picker::new(
|
let picker = Picker::new(
|
||||||
Delegate {
|
Delegate {
|
||||||
candidates: vec![
|
candidates: vec![
|
||||||
"Baguette (France)".into(),
|
"Baguette (France)".into(),
|
||||||
@@ -148,7 +143,9 @@ impl PickerStory {
|
|||||||
selected_ix: 0,
|
selected_ix: 0,
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
)
|
);
|
||||||
|
picker.focus(cx);
|
||||||
|
picker
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user