From 5dbd23f6b095d182cf320ebfe6248f2fafbac013 Mon Sep 17 00:00:00 2001 From: blufony <79605864+blufony@users.noreply.github.com> Date: Sat, 27 Apr 2024 02:22:15 +0200 Subject: [PATCH] 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 --- assets/keymaps/vim.json | 3 ++- crates/project_panel/src/project_panel.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.json index 24593404df..1f9fbda076 100644 --- a/assets/keymaps/vim.json +++ b/assets/keymaps/vim.json @@ -627,7 +627,8 @@ "p": "project_panel::Open", "x": "project_panel::RevealInFinder", "shift-g": "menu::SelectLast", - "g g": "menu::SelectFirst" + "g g": "menu::SelectFirst", + "-": "project_panel::SelectParent" } } ] diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index f55c9d5471..f8d297728f 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -134,6 +134,7 @@ actions!( NewSearchInDirectory, UnfoldDirectory, FoldDirectory, + SelectParent, ] ); @@ -993,6 +994,23 @@ impl ProjectPanel { } } + fn select_parent(&mut self, _: &SelectParent, cx: &mut ViewContext) { + 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) { let worktree = self .visible_entries @@ -1772,6 +1790,7 @@ impl Render for ProjectPanel { .on_action(cx.listener(Self::select_prev)) .on_action(cx.listener(Self::select_first)) .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::collapse_selected_entry)) .on_action(cx.listener(Self::collapse_all_entries))