From bfb8f24acd39a1331a5b66324b9600dfeb9da692 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Wed, 30 Jul 2025 13:03:43 +0530 Subject: [PATCH] project_panel: Fix autoscroll to treat entries behind sticky items as out of viewport (cherry-pick #35067) (#35315) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cherry-picked project_panel: Fix autoscroll to treat entries behind sticky items as out of viewport (#35067) Closes #34831 Autoscroll centers items only if they’re out of viewport. Before this PR, entry behind sticky items was not considered out of viewport, and hence actions like `reveal in project panel` or focusing buffer would not autoscroll that entry into the view in that case. This PR fixes that by using recently added `scroll_to_item_with_offset` in https://github.com/zed-industries/zed/pull/35064. Release Notes: - Fixed issue where `pane: reveal in project panel` action was not working if the entry was behind sticky items. Co-authored-by: Smit Barmase --- crates/project_panel/src/project_panel.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 82dc45b7bf8512d3000831ef05c97d104d4ad94f..b8a7aa222060860d437fecb2aa0dff8fe06a2c47 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -114,6 +114,7 @@ pub struct ProjectPanel { mouse_down: bool, hover_expand_task: Option>, previous_drag_position: Option>, + sticky_items_count: usize, } struct DragTargetEntry { @@ -572,6 +573,9 @@ impl ProjectPanel { if project_panel_settings.hide_root != new_settings.hide_root { this.update_visible_entries(None, cx); } + if project_panel_settings.sticky_scroll && !new_settings.sticky_scroll { + this.sticky_items_count = 0; + } project_panel_settings = new_settings; this.update_diagnostics(cx); cx.notify(); @@ -615,6 +619,7 @@ impl ProjectPanel { mouse_down: false, hover_expand_task: None, previous_drag_position: None, + sticky_items_count: 0, }; this.update_visible_entries(None, cx); @@ -2267,8 +2272,11 @@ impl ProjectPanel { fn autoscroll(&mut self, cx: &mut Context) { if let Some((_, _, index)) = self.selection.and_then(|s| self.index_for_selection(s)) { - self.scroll_handle - .scroll_to_item(index, ScrollStrategy::Center); + self.scroll_handle.scroll_to_item_with_offset( + index, + ScrollStrategy::Center, + self.sticky_items_count, + ); cx.notify(); } } @@ -5363,7 +5371,10 @@ impl Render for ProjectPanel { items }, |this, marker_entry, window, cx| { - this.render_sticky_entries(marker_entry, window, cx) + let sticky_entries = + this.render_sticky_entries(marker_entry, window, cx); + this.sticky_items_count = sticky_entries.len(); + sticky_entries }, ); list.with_decoration(if show_indent_guides {