From ecabee02da682dd972048f8e9df8cf09becc8e6a Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Wed, 1 Dec 2021 09:28:22 +0100 Subject: [PATCH] allow opening file selected in tree (#989) --- CHANGELOG.md | 1 + src/components/revision_files.rs | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bda438bf..3499ef96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The way this works got changed and simplified ([See docs](https://github.com/ext - simplify key overrides ([see docs](https://github.com/extrawurst/gitui/blob/master/KEY_CONFIG.md)) ([#946](https://github.com/extrawurst/gitui/issues/946)) - dedicated fuzzy finder up/down keys to allow vim overrides ([#993](https://github.com/extrawurst/gitui/pull/993)) - pull will also download tags ([#1013](https://github.com/extrawurst/gitui/pull/1013)) +- allow editing file from filetree ([#989](https://github.com/extrawurst/gitui/pull/989)) ### Fixed - honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933)) diff --git a/src/components/revision_files.rs b/src/components/revision_files.rs index ba98bf3e..5f9116b7 100644 --- a/src/components/revision_files.rs +++ b/src/components/revision_files.rs @@ -155,13 +155,15 @@ impl RevisionFilesComponent { } } - fn selection_changed(&mut self) { - //TODO: retrieve TreeFile from tree datastructure - if let Some(file) = self - .tree + fn selected_file(&self) -> Option { + self.tree .selected_file() .map(|file| file.full_path_str().to_string()) - { + } + + fn selection_changed(&mut self) { + //TODO: retrieve TreeFile from tree datastructure + if let Some(file) = self.selected_file() { log::info!("selected: {:?}", file); let path = Path::new(&file); if let Some(item) = @@ -271,6 +273,11 @@ impl Component for RevisionFilesComponent { ) .order(order::NAV), ); + out.push(CommandInfo::new( + strings::commands::edit_item(&self.key_config), + self.tree.selected_file().is_some(), + true, + )); tree_nav_cmds(&self.tree, &self.key_config, out); } else { self.current_file.commands(out, force_all); @@ -314,6 +321,16 @@ impl Component for RevisionFilesComponent { self.open_finder(); return Ok(EventState::Consumed); } + } else if key == self.key_config.keys.edit_file { + if let Some(file) = self.selected_file() { + //Note: switch to status tab so its clear we are + // not altering a file inside a revision here + self.queue.push(InternalEvent::TabSwitch); + self.queue.push( + InternalEvent::OpenExternalEditor(Some(file)), + ); + return Ok(EventState::Consumed); + } } else if !is_tree_focused { return self.current_file.event(event); }