From a47fd1d723245de9fa136c9fa152b0498d99ce08 Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Mon, 26 May 2025 13:06:19 +0200 Subject: [PATCH] Ensure horizontal scrollbars show as needed (#30964) This PR fixes an issue where the horizontal scrollbar was sometimes not rendered despite being needed for the outline and project panels. The issue occured since `self.width` does not neccessarily have to be set when the scrollbar is rendered (it is only set on panel resize). However, the check for a `width` is not needed at all since the scrollbar constructor determines whether a scrollbar has to be rendered or not. Hence, this does not need to be special-cased. Furthermore, since `Scrollbar::horizontal()` returns `Some(...)` when a scrollbar needs to be rendered, we do not have to check for this seperately on the scroll handle and can just map on the option. This simplifies the code a bit. | `main` | This PR | | --- | --- | | ![main](https://github.com/user-attachments/assets/db1d4524-716e-42c1-a6f9-7cfd59c94b30) | ![PR](https://github.com/user-attachments/assets/12536d28-616e-487d-b948-653f53da36b4) | Release Notes: - Fixed an issue where the horizontal scrollbar would not render in the project and outline panels. --- crates/outline_panel/src/outline_panel.rs | 22 +++------------------- crates/project_panel/src/project_panel.rs | 22 +++------------------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rs index de3af65d58..cfde0ce9fb 100644 --- a/crates/outline_panel/src/outline_panel.rs +++ b/crates/outline_panel/src/outline_panel.rs @@ -4335,19 +4335,7 @@ impl OutlinePanel { { return None; } - - let scroll_handle = self.scroll_handle.0.borrow(); - let longest_item_width = scroll_handle - .last_item_size - .filter(|size| size.contents.width > size.item.width)? - .contents - .width - .0 as f64; - if longest_item_width < scroll_handle.base_handle.bounds().size.width.0 as f64 { - return None; - } - - Some( + Scrollbar::horizontal(self.horizontal_scrollbar_state.clone()).map(|scrollbar| { div() .occlude() .id("project-panel-horizontal-scroll") @@ -4384,12 +4372,8 @@ impl OutlinePanel { .bottom_0() .h(px(12.)) .cursor_default() - .when(self.width.is_some(), |this| { - this.children(Scrollbar::horizontal( - self.horizontal_scrollbar_state.clone(), - )) - }), - ) + .child(scrollbar) + }) } fn should_show_scrollbar(cx: &App) -> bool { diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index a188546dfa..9b8992fc6c 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -4340,19 +4340,7 @@ impl ProjectPanel { { return None; } - - let scroll_handle = self.scroll_handle.0.borrow(); - let longest_item_width = scroll_handle - .last_item_size - .filter(|size| size.contents.width > size.item.width)? - .contents - .width - .0 as f64; - if longest_item_width < scroll_handle.base_handle.bounds().size.width.0 as f64 { - return None; - } - - Some( + Scrollbar::horizontal(self.horizontal_scrollbar_state.clone()).map(|scrollbar| { div() .occlude() .id("project-panel-horizontal-scroll") @@ -4389,12 +4377,8 @@ impl ProjectPanel { .bottom_1() .h(px(12.)) .cursor_default() - .when(self.width.is_some(), |this| { - this.children(Scrollbar::horizontal( - self.horizontal_scrollbar_state.clone(), - )) - }), - ) + .child(scrollbar) + }) } fn dispatch_context(&self, window: &Window, cx: &Context) -> KeyContext {