From 6e4f7470413ab709f766793cd23c0aa65700cf99 Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Fri, 25 Jul 2025 06:21:38 +0530 Subject: [PATCH] project_panel: Fix autoscroll to treat entries behind sticky items as out of viewport (#35067) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- 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 dd680981fc..05e6bfe4df 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(); } } @@ -5344,7 +5352,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 {