list: Fix the scroll_to_item not working (#1129)

This commit is contained in:
Floyd Wang 2025-08-13 15:12:54 +08:00 committed by GitHub
parent e37369ea16
commit 37de698a61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 13 deletions

View file

@ -523,14 +523,7 @@ impl Render for ListStory {
.small()
.on_click(cx.listener(|this, _, window, cx| {
this.company_list.update(cx, |list, cx| {
if let Some(selected) = list.selected_index() {
list.scroll_to_item(
selected,
ScrollStrategy::Top,
window,
cx,
);
}
list.scroll_to_selected_item(window, cx);
})
})),
)

View file

@ -202,7 +202,7 @@ where
pub fn scroll_to_item(
&mut self,
ix: IndexPath,
_strategy: ScrollStrategy,
strategy: ScrollStrategy,
_: &mut Window,
cx: &mut Context<Self>,
) {
@ -215,7 +215,7 @@ where
return;
}
self.deferred_scroll_to_index = Some(ix);
self.scroll_handle.scroll_to_item(ix.row, strategy);
cx.notify();
}
@ -224,10 +224,12 @@ where
&self.scroll_handle
}
pub fn scroll_to_selected_item(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
pub fn scroll_to_selected_item(&mut self, _: &mut Window, cx: &mut Context<Self>) {
if let Some(ix) = self.selected_index {
self.deferred_scroll_to_index = Some(ix);
cx.notify();
if let Some(ix) = self.rows_cache.position_of(&ix) {
self.scroll_handle.scroll_to_item(ix, ScrollStrategy::Top);
cx.notify();
}
}
}