From 65759d43163bd36cce8f8aa492ba2628ca005a7a Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 24 Jul 2025 16:27:29 +0800 Subject: [PATCH] gpui: Fix Interactivity prepaint to update scroll_handle bounds (#35013) It took a long time to check this problem. Finally, I found that due to a detail missing when changing #34832, the bounds of `ScrollHandle` was not updated in the Interactivity `prepaint` phase. ```diff - scroll_handle_state.padded_content_size = padded_content_size; + scroll_handle_state.max_offset = scroll_max; ``` It was correct before the change, because the `padded_content_size` (including `bounds.size`) was saved before, and the bounds was missing after changing to `max_offset`, but the bounds were not updated anywhere. So when `scroll_handle.bounds()` is obtained outside, it is always 0px here. @MrSubidubi Release Notes: - N/A --- crates/gpui/src/elements/div.rs | 7 +------ crates/gpui/src/elements/uniform_list.rs | 5 ++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index 4655c92409d3f21fd8a2a919154368a56da9567e..fa47758581d79399fad4530e00e62bc311bab515 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -1334,7 +1334,6 @@ impl Element for Div { } else if let Some(scroll_handle) = self.interactivity.tracked_scroll_handle.as_ref() { let mut state = scroll_handle.0.borrow_mut(); state.child_bounds = Vec::with_capacity(request_layout.child_layout_ids.len()); - state.bounds = bounds; for child_layout_id in &request_layout.child_layout_ids { let child_bounds = window.layout_bounds(*child_layout_id); child_min = child_min.min(&child_bounds.origin); @@ -1706,6 +1705,7 @@ impl Interactivity { if let Some(mut scroll_handle_state) = tracked_scroll_handle { scroll_handle_state.max_offset = scroll_max; + scroll_handle_state.bounds = bounds; } *scroll_offset @@ -3007,11 +3007,6 @@ impl ScrollHandle { self.0.borrow().bounds } - /// Set the bounds into which this child is painted - pub(super) fn set_bounds(&self, bounds: Bounds) { - self.0.borrow_mut().bounds = bounds; - } - /// Get the bounds for a specific child. pub fn bounds_for_item(&self, ix: usize) -> Option> { self.0.borrow().child_bounds.get(ix).cloned() diff --git a/crates/gpui/src/elements/uniform_list.rs b/crates/gpui/src/elements/uniform_list.rs index 52e2015c20f9983e78c126cc920ed115eef0fd7a..e80656a07878f640843afa747d2d48e4448acdc5 100644 --- a/crates/gpui/src/elements/uniform_list.rs +++ b/crates/gpui/src/elements/uniform_list.rs @@ -295,9 +295,8 @@ impl Element for UniformList { bounds.bottom_right() - point(border.right + padding.right, border.bottom), ); - let y_flipped = if let Some(scroll_handle) = self.scroll_handle.as_mut() { - let mut scroll_state = scroll_handle.0.borrow_mut(); - scroll_state.base_handle.set_bounds(bounds); + let y_flipped = if let Some(scroll_handle) = &self.scroll_handle { + let scroll_state = scroll_handle.0.borrow(); scroll_state.y_flipped } else { false