From f57ff1c660d85e596dcbfa8237f8c7471822c7d7 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 10 Jan 2024 12:16:06 +0200 Subject: [PATCH] Make the scroll position updated as soon as possible to the correct deferred value Co-Authored-By: Antonio Scandurra --- crates/gpui/src/elements/uniform_list.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/gpui/src/elements/uniform_list.rs b/crates/gpui/src/elements/uniform_list.rs index 244e8cde088be5942ad4a5887733b8b9795adbd7..793474f10b42cf429d66be2daaaa35b1cddc5a3d 100644 --- a/crates/gpui/src/elements/uniform_list.rs +++ b/crates/gpui/src/elements/uniform_list.rs @@ -95,6 +95,7 @@ impl UniformListScrollHandle { } else if item_bottom > scroll_top + state.list_height { scroll_offset.y = -(item_bottom - state.list_height); } + self.deferred_scroll_to_item = None; } else { self.deferred_scroll_to_item = Some(ix); } @@ -104,7 +105,6 @@ impl UniformListScrollHandle { if let Some(state) = &*self.state.borrow() { -state.scroll_offset.borrow().y } else { - self.deferred_scroll_to_item = Some(0); Pixels::ZERO } } @@ -241,12 +241,15 @@ impl Element for UniformList { scroll_handle.state.borrow_mut().replace(ScrollHandleState { item_height, list_height: padded_bounds.size.height, - scroll_offset: shared_scroll_offset, + scroll_offset: shared_scroll_offset.clone(), }); - if let Some(ix) = scroll_handle.deferred_scroll_to_item.take() { - dbg!("@@@@"); - scroll_handle.scroll_to_item(ix); - cx.notify(); + if let Some(scroll_handle) = self.scroll_handle.as_mut() { + if scroll_handle.state.borrow().is_some() { + if let Some(ix) = scroll_handle.deferred_scroll_to_item.take() { + scroll_handle.scroll_to_item(ix); + scroll_offset = *shared_scroll_offset.borrow(); + } + } } }