Simplify ListState
API (#35685)
Follow up to: https://github.com/zed-industries/zed/pull/35670, simplifies the List state APIs so you no longer have to worry about strong vs. weak pointers when rendering list items. Release Notes: - N/A --------- Co-authored-by: Agus Zubiaga <agus@zed.dev>
This commit is contained in:
parent
d0de81b0b4
commit
53175263a1
15 changed files with 322 additions and 403 deletions
|
@ -126,29 +126,7 @@ impl NotebookEditor {
|
|||
let cell_count = cell_order.len();
|
||||
|
||||
let this = cx.entity();
|
||||
let cell_list = ListState::new(
|
||||
cell_count,
|
||||
gpui::ListAlignment::Top,
|
||||
px(1000.),
|
||||
move |ix, window, cx| {
|
||||
notebook_handle
|
||||
.upgrade()
|
||||
.and_then(|notebook_handle| {
|
||||
notebook_handle.update(cx, |notebook, cx| {
|
||||
notebook
|
||||
.cell_order
|
||||
.get(ix)
|
||||
.and_then(|cell_id| notebook.cell_map.get(cell_id))
|
||||
.map(|cell| {
|
||||
notebook
|
||||
.render_cell(ix, cell, window, cx)
|
||||
.into_any_element()
|
||||
})
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|| div().into_any())
|
||||
},
|
||||
);
|
||||
let cell_list = ListState::new(cell_count, gpui::ListAlignment::Top, px(1000.));
|
||||
|
||||
Self {
|
||||
project,
|
||||
|
@ -544,7 +522,19 @@ impl Render for NotebookEditor {
|
|||
.flex_1()
|
||||
.size_full()
|
||||
.overflow_y_scroll()
|
||||
.child(list(self.cell_list.clone()).size_full()),
|
||||
.child(list(
|
||||
self.cell_list.clone(),
|
||||
cx.processor(|this, ix, window, cx| {
|
||||
this.cell_order
|
||||
.get(ix)
|
||||
.and_then(|cell_id| this.cell_map.get(cell_id))
|
||||
.map(|cell| {
|
||||
this.render_cell(ix, cell, window, cx).into_any_element()
|
||||
})
|
||||
.unwrap_or_else(|| div().into_any())
|
||||
}),
|
||||
))
|
||||
.size_full(),
|
||||
)
|
||||
.child(self.render_notebook_controls(window, cx))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue