Skip to content

Commit 9c17231

Browse files
committed
Add history shortcut to tree in files tab
1 parent 8891ea1 commit 9c17231

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

src/components/revision_files.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,30 @@ impl RevisionFilesComponent {
130130
}
131131

132132
fn blame(&self) -> bool {
133-
self.tree.selected_file().map_or(false, |file| {
134-
self.queue.push(InternalEvent::BlameFile(
135-
file.full_path_str()
136-
.strip_prefix("./")
137-
.unwrap_or_default()
138-
.to_string(),
139-
));
133+
self.selected_file_path().map_or(false, |path| {
134+
self.queue.push(InternalEvent::BlameFile(path));
135+
136+
true
137+
})
138+
}
139+
140+
fn file_history(&self) -> bool {
141+
self.selected_file_path().map_or(false, |path| {
142+
self.queue.push(InternalEvent::OpenFileRevlog(path));
143+
140144
true
141145
})
142146
}
143147

148+
fn selected_file_path(&self) -> Option<String> {
149+
self.tree.selected_file().map(|file| {
150+
file.full_path_str()
151+
.strip_prefix("./")
152+
.unwrap_or_default()
153+
.to_string()
154+
})
155+
}
156+
144157
fn selection_changed(&mut self) {
145158
//TODO: retrieve TreeFile from tree datastructure
146159
if let Some(file) = self
@@ -254,6 +267,16 @@ impl Component for RevisionFilesComponent {
254267
)
255268
.order(order::NAV),
256269
);
270+
out.push(
271+
CommandInfo::new(
272+
strings::commands::open_file_history(
273+
&self.key_config,
274+
),
275+
self.tree.selected_file().is_some(),
276+
true,
277+
)
278+
.order(order::RARE_ACTION),
279+
);
257280
tree_nav_cmds(&self.tree, &self.key_config, out);
258281
} else {
259282
self.current_file.commands(out, force_all);
@@ -278,6 +301,11 @@ impl Component for RevisionFilesComponent {
278301
self.hide();
279302
return Ok(EventState::Consumed);
280303
}
304+
} else if key == self.key_config.file_history {
305+
if self.file_history() {
306+
self.hide();
307+
return Ok(EventState::Consumed);
308+
}
281309
} else if key == self.key_config.move_right {
282310
if is_tree_focused {
283311
self.focus = Focus::File;

0 commit comments

Comments
 (0)