Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-11-07 13:03:36 -08:00
parent 10c94cc8b7
commit 80e6427eec

View file

@ -41,18 +41,13 @@ impl<V: PickerDelegate> Picker<V> {
phantom: std::marker::PhantomData, phantom: std::marker::PhantomData,
} }
} }
}
impl<V: 'static + PickerDelegate> Picker<V> { fn bind_actions<T: StatelessInteractive<V>>(
pub fn render(self, view: &mut V, _cx: &mut ViewContext<V>) -> impl Component<V> { div: T,
let id = self.id.clone(); id: ElementId,
let scroll_handle = UniformListScrollHandle::new(); scroll_handle: &UniformListScrollHandle,
div() ) -> T {
.size_full() div.on_action({
.id(self.id.clone())
.track_focus(&self.focus_handle)
.context("picker")
.on_action({
let id = id.clone(); let id = id.clone();
let scroll_handle = scroll_handle.clone(); let scroll_handle = scroll_handle.clone();
move |view: &mut V, _: &menu::SelectNext, cx| { move |view: &mut V, _: &menu::SelectNext, cx| {
@ -118,6 +113,19 @@ impl<V: 'static + PickerDelegate> Picker<V> {
view.confirm(true, id.clone(), cx); view.confirm(true, id.clone(), cx);
} }
}) })
}
}
impl<V: 'static + PickerDelegate> Picker<V> {
pub fn render(self, view: &mut V, _cx: &mut ViewContext<V>) -> impl Component<V> {
let id = self.id.clone();
let scroll_handle = UniformListScrollHandle::new();
Self::bind_actions(
div()
.id(self.id.clone())
.size_full()
.track_focus(&self.focus_handle)
.context("picker")
.child( .child(
uniform_list( uniform_list(
"candidates", "candidates",
@ -125,12 +133,17 @@ impl<V: 'static + PickerDelegate> Picker<V> {
move |view: &mut V, visible_range, cx| { move |view: &mut V, visible_range, cx| {
let selected_ix = view.selected_index(self.id.clone()); let selected_ix = view.selected_index(self.id.clone());
visible_range visible_range
.map(|ix| view.render_match(ix, ix == selected_ix, self.id.clone(), cx)) .map(|ix| {
view.render_match(ix, ix == selected_ix, self.id.clone(), cx)
})
.collect() .collect()
}, },
) )
.track_scroll(scroll_handle.clone()) .track_scroll(scroll_handle.clone())
.size_full(), .size_full(),
),
id,
&scroll_handle,
) )
} }
} }