From 572e29585458d88dbb048b212e2a04e7dd2c85f3 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 14 Jun 2022 13:56:56 +0200 Subject: [PATCH] Open files in project panel using `enter` instead of `right` --- crates/project_panel/src/project_panel.rs | 39 +++++++++++++++-------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index e34c1bce18..bbd64efe17 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -289,14 +289,14 @@ impl ProjectPanel { fn expand_selected_entry(&mut self, _: &ExpandSelectedEntry, cx: &mut ViewContext) { if let Some((worktree, entry)) = self.selected_entry(cx) { - let expanded_dir_ids = - if let Some(expanded_dir_ids) = self.expanded_dir_ids.get_mut(&worktree.id()) { - expanded_dir_ids - } else { - return; - }; - if entry.is_dir() { + let expanded_dir_ids = + if let Some(expanded_dir_ids) = self.expanded_dir_ids.get_mut(&worktree.id()) { + expanded_dir_ids + } else { + return; + }; + match expanded_dir_ids.binary_search(&entry.id) { Ok(_) => self.select_next(&SelectNext, cx), Err(ix) => { @@ -305,12 +305,6 @@ impl ProjectPanel { cx.notify(); } } - } else { - let event = Event::OpenedEntry { - entry_id: entry.id, - focus_opened_item: true, - }; - cx.emit(event); } } } @@ -392,6 +386,25 @@ 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) { + if entry.is_file() { + self.open_entry( + &Open { + entry_id: entry.id, + change_focus: true, + }, + cx, + ); + } + None + } else { + None + } + } + + fn confirm_edit(&mut self, cx: &mut ViewContext) -> Option>> { let edit_state = self.edit_state.as_mut()?; cx.focus_self();