mirror of
https://github.com/zed-industries/zed.git
synced 2026-06-01 03:14:56 +07:00
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 <heysmitbarmase@gmail.com>
This commit is contained in:
parent
fb06aa94a1
commit
2c7bfec297
1 changed files with 29 additions and 6 deletions
|
|
@ -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<String> {
|
||||
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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue