project_panel: Fix autoscroll to treat entries behind sticky items as out of viewport (cherry-pick #35067) (#35315)

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 <heysmitbarmase@gmail.com>
This commit is contained in:
gcp-cherry-pick-bot[bot] 2025-07-30 13:03:43 +05:30 committed by GitHub
parent 4fd3e220db
commit bfb8f24acd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -114,6 +114,7 @@ pub struct ProjectPanel {
mouse_down: bool,
hover_expand_task: Option<Task<()>>,
previous_drag_position: Option<Point<Pixels>>,
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<Self>) {
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 {