vim: add keybinding to jump to parent directory in project panel (#11078)

Release Notes:

- vim: Support `-` to go to `parent directory` of the project panel.

As mentioned in the comments of #11073 this adds support for netrw's `-`
to go to the parent directory in the project panel. Again tested on
linux only.


- N/A
This commit is contained in:
blufony 2024-04-27 02:22:15 +02:00 committed by GitHub
parent b7d9aeb29d
commit 5dbd23f6b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -627,7 +627,8 @@
"p": "project_panel::Open", "p": "project_panel::Open",
"x": "project_panel::RevealInFinder", "x": "project_panel::RevealInFinder",
"shift-g": "menu::SelectLast", "shift-g": "menu::SelectLast",
"g g": "menu::SelectFirst" "g g": "menu::SelectFirst",
"-": "project_panel::SelectParent"
} }
} }
] ]

View File

@ -134,6 +134,7 @@ actions!(
NewSearchInDirectory, NewSearchInDirectory,
UnfoldDirectory, UnfoldDirectory,
FoldDirectory, FoldDirectory,
SelectParent,
] ]
); );
@ -993,6 +994,23 @@ impl ProjectPanel {
} }
} }
fn select_parent(&mut self, _: &SelectParent, cx: &mut ViewContext<Self>) {
if let Some((worktree, entry)) = self.selected_entry(cx) {
if let Some(parent) = entry.path.parent() {
if let Some(parent_entry) = worktree.entry_for_path(parent) {
self.selection = Some(Selection {
worktree_id: worktree.id(),
entry_id: parent_entry.id,
});
self.autoscroll(cx);
cx.notify();
}
}
} else {
self.select_first(&SelectFirst {}, cx);
}
}
fn select_first(&mut self, _: &SelectFirst, cx: &mut ViewContext<Self>) { fn select_first(&mut self, _: &SelectFirst, cx: &mut ViewContext<Self>) {
let worktree = self let worktree = self
.visible_entries .visible_entries
@ -1772,6 +1790,7 @@ impl Render for ProjectPanel {
.on_action(cx.listener(Self::select_prev)) .on_action(cx.listener(Self::select_prev))
.on_action(cx.listener(Self::select_first)) .on_action(cx.listener(Self::select_first))
.on_action(cx.listener(Self::select_last)) .on_action(cx.listener(Self::select_last))
.on_action(cx.listener(Self::select_parent))
.on_action(cx.listener(Self::expand_selected_entry)) .on_action(cx.listener(Self::expand_selected_entry))
.on_action(cx.listener(Self::collapse_selected_entry)) .on_action(cx.listener(Self::collapse_selected_entry))
.on_action(cx.listener(Self::collapse_all_entries)) .on_action(cx.listener(Self::collapse_all_entries))