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,
}
}
}
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();
div()
.size_full()
.id(self.id.clone())
.track_focus(&self.focus_handle)
.context("picker")
.on_action({
fn bind_actions<T: StatelessInteractive<V>>(
div: T,
id: ElementId,
scroll_handle: &UniformListScrollHandle,
) -> T {
div.on_action({
let id = id.clone();
let scroll_handle = scroll_handle.clone();
move |view: &mut V, _: &menu::SelectNext, cx| {
@ -118,6 +113,19 @@ impl<V: 'static + PickerDelegate> Picker<V> {
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(
uniform_list(
"candidates",
@ -125,12 +133,17 @@ impl<V: 'static + PickerDelegate> Picker<V> {
move |view: &mut V, visible_range, cx| {
let selected_ix = view.selected_index(self.id.clone());
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()
},
)
.track_scroll(scroll_handle.clone())
.size_full(),
),
id,
&scroll_handle,
)
}
}