Skip to content

Commit ecabee0

Browse files
author
Stephan Dilly
committed
allow opening file selected in tree (#989)
1 parent 36699a0 commit ecabee0

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The way this works got changed and simplified ([See docs](https://github.com/ext
2929
- simplify key overrides ([see docs](https://github.com/extrawurst/gitui/blob/master/KEY_CONFIG.md)) ([#946](https://github.com/extrawurst/gitui/issues/946))
3030
- dedicated fuzzy finder up/down keys to allow vim overrides ([#993](https://github.com/extrawurst/gitui/pull/993))
3131
- pull will also download tags ([#1013](https://github.com/extrawurst/gitui/pull/1013))
32+
- allow editing file from filetree ([#989](https://github.com/extrawurst/gitui/pull/989))
3233

3334
### Fixed
3435
- honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933))

src/components/revision_files.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,15 @@ impl RevisionFilesComponent {
155155
}
156156
}
157157

158-
fn selection_changed(&mut self) {
159-
//TODO: retrieve TreeFile from tree datastructure
160-
if let Some(file) = self
161-
.tree
158+
fn selected_file(&self) -> Option<String> {
159+
self.tree
162160
.selected_file()
163161
.map(|file| file.full_path_str().to_string())
164-
{
162+
}
163+
164+
fn selection_changed(&mut self) {
165+
//TODO: retrieve TreeFile from tree datastructure
166+
if let Some(file) = self.selected_file() {
165167
log::info!("selected: {:?}", file);
166168
let path = Path::new(&file);
167169
if let Some(item) =
@@ -271,6 +273,11 @@ impl Component for RevisionFilesComponent {
271273
)
272274
.order(order::NAV),
273275
);
276+
out.push(CommandInfo::new(
277+
strings::commands::edit_item(&self.key_config),
278+
self.tree.selected_file().is_some(),
279+
true,
280+
));
274281
tree_nav_cmds(&self.tree, &self.key_config, out);
275282
} else {
276283
self.current_file.commands(out, force_all);
@@ -314,6 +321,16 @@ impl Component for RevisionFilesComponent {
314321
self.open_finder();
315322
return Ok(EventState::Consumed);
316323
}
324+
} else if key == self.key_config.keys.edit_file {
325+
if let Some(file) = self.selected_file() {
326+
//Note: switch to status tab so its clear we are
327+
// not altering a file inside a revision here
328+
self.queue.push(InternalEvent::TabSwitch);
329+
self.queue.push(
330+
InternalEvent::OpenExternalEditor(Some(file)),
331+
);
332+
return Ok(EventState::Consumed);
333+
}
317334
} else if !is_tree_focused {
318335
return self.current_file.event(event);
319336
}

0 commit comments

Comments
 (0)