From bdd0b9f3878d3548c03d7f70d219172b655c7443 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Mon, 24 Jul 2023 16:35:01 -0400 Subject: [PATCH] Add open file in project finder via space (#2785) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @mikayla-maki for 👀 [This PR added in the ability to rename a file via `enter`](https://github.com/zed-industries/zed/pull/2784). Previously, `enter` was used to both open a file and confirm a rename, so this PR changes the opening of a file to use `space`, which is what VS Code uses. It also makes a bit more sense because now `enter` is just used to start a rename and confirm the rename, vs being used for 2 different actions. N/A on the release notes, as I adjusted the release note in the previously-tagged PR. Release Notes: - N/A --- assets/keymaps/default.json | 1 + crates/project_panel/src/project_panel.rs | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 5c1002a5fc6015c6d31c658a57759b2686c1d671..7553c199258a2b21337e4984ecca3c818de2ba7d 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -529,6 +529,7 @@ "alt-cmd-shift-c": "project_panel::CopyRelativePath", "f2": "project_panel::Rename", "enter": "project_panel::Rename", + "space": "project_panel::Open", "backspace": "project_panel::Delete", "alt-cmd-r": "project_panel::RevealInFinder", "alt-shift-f": "project_panel::NewSearchInDirectory" diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 2a6da7db28950972dd09afe7a3cb3b646b89e7c3..3e20c4986e30e037c0b408dfffba8f192ce0b1d5 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -125,6 +125,7 @@ actions!( Paste, Delete, Rename, + Open, ToggleFocus, NewSearchInDirectory, ] @@ -146,6 +147,7 @@ pub fn init(assets: impl AssetSource, cx: &mut AppContext) { cx.add_action(ProjectPanel::rename); cx.add_async_action(ProjectPanel::delete); cx.add_async_action(ProjectPanel::confirm); + cx.add_async_action(ProjectPanel::open_file); cx.add_action(ProjectPanel::cancel); cx.add_action(ProjectPanel::cut); cx.add_action(ProjectPanel::copy); @@ -560,15 +562,20 @@ impl ProjectPanel { fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext) -> Option>> { if let Some(task) = self.confirm_edit(cx) { - Some(task) - } else if let Some((_, entry)) = self.selected_entry(cx) { + return Some(task); + } + + None + } + + fn open_file(&mut self, _: &Open, cx: &mut ViewContext) -> Option>> { + if let Some((_, entry)) = self.selected_entry(cx) { if entry.is_file() { self.open_entry(entry.id, true, cx); } - None - } else { - None } + + None } fn confirm_edit(&mut self, cx: &mut ViewContext) -> Option>> { @@ -2382,7 +2389,7 @@ mod tests { toggle_expand_dir(&panel, "src/test", cx); select_path(&panel, "src/test/first.rs", cx); - panel.update(cx, |panel, cx| panel.confirm(&Confirm, cx)); + panel.update(cx, |panel, cx| panel.open_file(&Open, cx)); cx.foreground().run_until_parked(); assert_eq!( visible_entries_as_strings(&panel, 0..10, cx), @@ -2410,7 +2417,7 @@ mod tests { ensure_no_open_items_and_panes(window_id, &workspace, cx); select_path(&panel, "src/test/second.rs", cx); - panel.update(cx, |panel, cx| panel.confirm(&Confirm, cx)); + panel.update(cx, |panel, cx| panel.open_file(&Open, cx)); cx.foreground().run_until_parked(); assert_eq!( visible_entries_as_strings(&panel, 0..10, cx),