project_panel: Fix sticky items horizontal scroll and hover propagation (#34367)

Release Notes:

- Fixed horizontal scrolling not working for sticky items in the Project
Panel.
- Fixed issue where hovering over the last sticky item in the Project
Panel showed a hovered state on the entry behind it.
- Improved behavior when clicking a sticky item in the Project Panel so
it scrolls just enough for the item to no longer be sticky.
This commit is contained in:
Smit Barmase 2025-07-12 17:44:30 -07:00 committed by GitHub
parent 8f6b9f0d65
commit 1cadff9311
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 95 additions and 74 deletions

View file

@ -3961,8 +3961,14 @@ impl ProjectPanel {
linear_color_stop(shadow_color_bottom, 0.),
));
let id: ElementId = if is_sticky {
SharedString::from(format!("project_panel_sticky_item_{}", entry_id.to_usize())).into()
} else {
(entry_id.to_proto() as usize).into()
};
div()
.id(entry_id.to_proto() as usize)
.id(id.clone())
.relative()
.group(GROUP_NAME)
.cursor_pointer()
@ -3973,6 +3979,9 @@ impl ProjectPanel {
.border_color(border_color)
.hover(|style| style.bg(bg_hover_color).border_color(border_hover_color))
.when(show_sticky_shadow, |this| this.child(sticky_shadow))
.when(is_sticky, |this| {
this.block_mouse_except_scroll()
})
.when(!is_sticky, |this| {
this
.when(is_highlighted && folded_directory_drag_target.is_none(), |this| this.border_color(transparent_white()).bg(item_colors.drag_over))
@ -4183,6 +4192,16 @@ impl ProjectPanel {
.unwrap_or(ScrollStrategy::Top);
this.scroll_handle.scroll_to_item(index, strategy);
cx.notify();
// move down by 1px so that clicked item
// don't count as sticky anymore
cx.on_next_frame(window, |_, window, cx| {
cx.on_next_frame(window, |this, _, cx| {
let mut offset = this.scroll_handle.offset();
offset.y += px(1.);
this.scroll_handle.set_offset(offset);
cx.notify();
});
});
return;
}
}
@ -4201,7 +4220,7 @@ impl ProjectPanel {
}),
)
.child(
ListItem::new(entry_id.to_proto() as usize)
ListItem::new(id)
.indent_level(depth)
.indent_step_size(px(settings.indent_size))
.spacing(match settings.entry_spacing {