From 2c7bfec29786e031494262966a8ba211b244f30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Eriksson?= Date: Tue, 6 Jan 2026 11:33:19 +0100 Subject: [PATCH] project_panel: Fix right-click target for folded directories (#45876) Closes #45635 Release Notes: - Fixed context menu in project panel targeting the wrong folder when right-clicking on folded directory paths. - Added hover feedback to folded path folders to indicate which folder will be targeted. Recording: https://github.com/user-attachments/assets/3209921a-b791-4eef-8eb7-1b5dc68374da --------- Co-authored-by: Smit Barmase --- crates/project_panel/src/project_panel.rs | 35 +++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 3f650d98c13fb1baefba6c42ebf4333ad7f6e645..7c8e8bfd1927e80f65195cc33d34bcfad7863855 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -369,6 +369,19 @@ impl FoldedAncestors { .saturating_sub(self.current_ancestor_depth) } + fn set_active_index(&mut self, index: usize) -> bool { + let new_depth = self + .max_ancestor_depth() + .saturating_sub(1) + .saturating_sub(index); + if self.current_ancestor_depth != new_depth { + self.current_ancestor_depth = new_depth; + true + } else { + false + } + } + fn active_component(&self, file_name: &str) -> Option { Path::new(file_name) .components() @@ -5101,6 +5114,9 @@ impl ProjectPanel { )); let label = div() .id(id) + .px_0p5() + .rounded_xs() + .hover(|style| style.bg(cx.theme().colors().element_active)) .when(!is_sticky,| div| { div .when(index != components_len - 1, |div|{ @@ -5150,14 +5166,21 @@ impl ProjectPanel { .on_mouse_down( MouseButton::Left, cx.listener(move |this, _, _, cx| { - if index != active_index - && let Some(folds) = - this.state.ancestors.get_mut(&entry_id) - { - folds.current_ancestor_depth = - components_len - 1 - index; + if let Some(folds) = this.state.ancestors.get_mut(&entry_id) { + if folds.set_active_index(index) { cx.notify(); } + } + }), + ) + .on_mouse_down( + MouseButton::Right, + cx.listener(move |this, _, _, cx| { + if let Some(folds) = this.state.ancestors.get_mut(&entry_id) { + if folds.set_active_index(index) { + cx.notify(); + } + } }), ) .child(