Skip to content

Commit 12f360b

Browse files
authored
Support GoToParent action in Detail and UserCommand views (#111)
* Support GoToParent action in Detail and UserCommand views * Fix helps * Update README
1 parent 93d6408 commit 12f360b

File tree

6 files changed

+49
-19
lines changed

6 files changed

+49
-19
lines changed

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,17 @@ The default key bindings can be overridden. Please refer to [default-keybind.tom
209209

210210
#### Commit Detail
211211

212-
| Key | Description | Corresponding keybind |
213-
| ----------------------------------- | ------------------------------- | ------------------------------- |
214-
| <kbd>Esc</kbd> <kbd>Backspace</kbd> | Close commit details | `close` `cancel` |
215-
| <kbd>Down/Up</kbd> <kbd>j/k</kbd> | Scroll down/up | `navigate_down` `navigate_up` |
216-
| <kbd>Ctrl-f/b</kbd> | Scroll page down/up | `page_down` `page_up` |
217-
| <kbd>Ctrl-d/u</kbd> | Scroll half page down/up | `half_page_down` `half_page_up` |
218-
| <kbd>g/G</kbd> | Go to top/bottom | `go_to_top` `go_to_bottom` |
219-
| <kbd>J/K</kbd> | Select older/newer commit | `select_down` `select_up` |
220-
| <kbd>c/C</kbd> | Copy commit short/full hash | `short_copy` `full_copy` |
221-
| <kbd>d</kbd> | Toggle custom user command view | `user_command_view_toggle_1` |
212+
| Key | Description | Corresponding keybind |
213+
| ------------------------------------ | ------------------------------- | ------------------------------- |
214+
| <kbd>Esc</kbd> <kbd>Backspace</kbd> | Close commit details | `close` `cancel` |
215+
| <kbd>Down/Up</kbd> <kbd>j/k</kbd> | Scroll down/up | `navigate_down` `navigate_up` |
216+
| <kbd>Ctrl-f/b</kbd> | Scroll page down/up | `page_down` `page_up` |
217+
| <kbd>Ctrl-d/u</kbd> | Scroll half page down/up | `half_page_down` `half_page_up` |
218+
| <kbd>g/G</kbd> | Go to top/bottom | `go_to_top` `go_to_bottom` |
219+
| <kbd>J/K</kbd> | Select older/newer commit | `select_down` `select_up` |
220+
| <kbd>Alt-Down</kbd> <kbd>Alt-j</kbd> | Select parent commit | `go_to_parent` |
221+
| <kbd>c/C</kbd> | Copy commit short/full hash | `short_copy` `full_copy` |
222+
| <kbd>d</kbd> | Toggle custom user command view | `user_command_view_toggle_1` |
222223

223224
#### Refs List
224225

@@ -233,15 +234,16 @@ The default key bindings can be overridden. Please refer to [default-keybind.tom
233234

234235
#### User Command
235236

236-
| Key | Description | Corresponding keybind |
237-
| ------------------------------------------------ | --------------------------- | ------------------------------- |
238-
| <kbd>Esc</kbd> <kbd>Backspace</kbd> <kbd>?</kbd> | Close user command | `close` `cancel` `help_toggle` |
239-
| <kbd>Down/Up</kbd> <kbd>j/k</kbd> | Scroll down/up | `navigate_down` `navigate_up` |
240-
| <kbd>J/K</kbd> | Scroll down/up | `select_down` `select_up` |
241-
| <kbd>Ctrl-f/b</kbd> | Scroll page down/up | `page_down` `page_up` |
242-
| <kbd>Ctrl-d/u</kbd> | Scroll half page down/up | `half_page_down` `half_page_up` |
243-
| <kbd>g/G</kbd> | Go to top/bottom | `go_to_top` `go_to_bottom` |
244-
| <kbd>J/K</kbd> | Select older/newer commit | `select_down` `select_up` |
237+
| Key | Description | Corresponding keybind |
238+
| ------------------------------------ | --------------------------- | ------------------------------- |
239+
| <kbd>Esc</kbd> <kbd>Backspace</kbd> | Close user command | `close` `cancel` |
240+
| <kbd>Down/Up</kbd> <kbd>j/k</kbd> | Scroll down/up | `navigate_down` `navigate_up` |
241+
| <kbd>J/K</kbd> | Scroll down/up | `select_down` `select_up` |
242+
| <kbd>Ctrl-f/b</kbd> | Scroll page down/up | `page_down` `page_up` |
243+
| <kbd>Ctrl-d/u</kbd> | Scroll half page down/up | `half_page_down` `half_page_up` |
244+
| <kbd>g/G</kbd> | Go to top/bottom | `go_to_top` `go_to_bottom` |
245+
| <kbd>J/K</kbd> | Select older/newer commit | `select_down` `select_up` |
246+
| <kbd>Alt-Down</kbd> <kbd>Alt-j</kbd> | Select parent commit | `go_to_parent` |
245247

246248
#### Help
247249

src/app.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ impl App<'_> {
236236
AppEvent::SelectNewerCommit => {
237237
self.select_newer_commit();
238238
}
239+
AppEvent::SelectParentCommit => {
240+
self.select_parent_commit();
241+
}
239242
AppEvent::CopyToClipboard { name, value } => {
240243
self.copy_to_clipboard(name, value);
241244
}
@@ -553,6 +556,14 @@ impl App<'_> {
553556
}
554557
}
555558

559+
fn select_parent_commit(&mut self) {
560+
if let View::Detail(ref mut view) = self.view {
561+
view.select_parent_commit(self.repository);
562+
} else if let View::UserCommand(ref mut view) = self.view {
563+
view.select_parent_commit(self.repository, self.view_area);
564+
}
565+
}
566+
556567
fn clear_status_line(&mut self) {
557568
self.status_line = StatusLine::None;
558569
}

src/event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub enum AppEvent {
2727
ClearHelp,
2828
SelectNewerCommit,
2929
SelectOlderCommit,
30+
SelectParentCommit,
3031
CopyToClipboard { name: String, value: String },
3132
ClearStatusLine,
3233
UpdateStatusInput(String, Option<u16>, Option<String>),

src/view/detail.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ impl<'a> DetailView<'a> {
105105
UserEvent::SelectUp => {
106106
self.tx.send(AppEvent::SelectNewerCommit);
107107
}
108+
UserEvent::GoToParent => {
109+
self.tx.send(AppEvent::SelectParentCommit);
110+
}
108111
UserEvent::ShortCopy => {
109112
self.copy_commit_short_hash();
110113
}
@@ -171,6 +174,10 @@ impl<'a> DetailView<'a> {
171174
self.update_selected_commit(repository, |state| state.select_prev());
172175
}
173176

177+
pub fn select_parent_commit(&mut self, repository: &Repository) {
178+
self.update_selected_commit(repository, |state| state.select_parent());
179+
}
180+
174181
fn update_selected_commit<F>(&mut self, repository: &Repository, update_commit_list_state: F)
175182
where
176183
F: FnOnce(&mut CommitListState<'a>),

src/view/help.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ fn build_lines(
290290
(vec![UserEvent::GoToBottom], "Go to bottom".into()),
291291
(vec![UserEvent::SelectDown], "Select older commit".into()),
292292
(vec![UserEvent::SelectUp], "Select newer commit".into()),
293+
(vec![UserEvent::GoToParent], "Select parent commit".into()),
293294
(vec![UserEvent::ShortCopy], "Copy commit short hash".into()),
294295
(vec![UserEvent::FullCopy], "Copy commit hash".into()),
295296
];
@@ -320,6 +321,7 @@ fn build_lines(
320321
(vec![UserEvent::GoToBottom], "Go to bottom".into()),
321322
(vec![UserEvent::SelectDown], "Select older commit".into()),
322323
(vec![UserEvent::SelectUp], "Select newer commit".into()),
324+
(vec![UserEvent::GoToParent], "Select parent commit".into()),
323325
];
324326
user_command_helps.extend(user_command_view_toggle_helps);
325327
let (user_command_key_lines, user_command_value_lines) = build_block_lines("User Command:", user_command_helps, color_theme, keybind);

src/view/user_command.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ impl<'a> UserCommandView<'a> {
130130
UserEvent::SelectUp => {
131131
self.tx.send(AppEvent::SelectNewerCommit);
132132
}
133+
UserEvent::GoToParent => {
134+
self.tx.send(AppEvent::SelectParentCommit);
135+
}
133136
UserEvent::HelpToggle => {
134137
self.tx.send(AppEvent::OpenHelp);
135138
}
@@ -194,6 +197,10 @@ impl<'a> UserCommandView<'a> {
194197
self.update_selected_commit(repository, view_area, |state| state.select_prev());
195198
}
196199

200+
pub fn select_parent_commit(&mut self, repository: &Repository, view_area: Rect) {
201+
self.update_selected_commit(repository, view_area, |state| state.select_parent());
202+
}
203+
197204
fn update_selected_commit<F>(
198205
&mut self,
199206
repository: &Repository,

0 commit comments

Comments
 (0)