Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "jump to parent commit" #64

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,21 @@ The default key bindings can be overridden. Please refer to [default-keybind.tom

#### Commit List

| Key | Description | Corresponding keybind |
| --------------------------------- | -------------------------------------------------- | -------------------------------------------- |
| <kbd>Down/Up</kbd> <kbd>j/k</kbd> | Move down/up | `navigate_down` `navigate_up` |
| <kbd>g/G</kbd> | Go to top/bottom | `go_to_top` `go_to_bottom` |
| <kbd>Ctrl-f/b</kbd> | Scroll page down/up | `page_down` `page_up` |
| <kbd>Ctrl-d/u</kbd> | Scroll half page down/up | `half_page_down` `half_page_up` |
| <kbd>Ctrl-e/y</kbd> | Scroll down/up | `scroll_down` `scroll_up` |
| <kbd>H/M/L</kbd> | Select top/middle/bottom of the screen | `select_top` `select_middle` `select_bottom` |
| <kbd>Enter</kbd> | Show commit details<br>Apply search (if searching) | `confirm` |
| <kbd>Tab</kbd> | Open refs list | `ref_list_toggle` |
| <kbd>/</kbd> | Start search | `search` |
| <kbd>Esc</kbd> | Cancel search | `cancel` |
| <kbd>n/N</kbd> | Go to next/previous search match | `go_to_next` `go_to_previous` |
| <kbd>c/C</kbd> | Copy commit short/full hash | `short_copy` `full_copy` |
| Key | Description | Corresponding keybind |
| ------------------------------------ | -------------------------------------------------- | -------------------------------------------- |
| <kbd>Down/Up</kbd> <kbd>j/k</kbd> | Move down/up | `navigate_down` `navigate_up` |
| <kbd>Alt-Down</kbd> <kbd>Alt-j</kbd> | Move to parent commit | `go_to_parent` |
| <kbd>g/G</kbd> | Go to top/bottom | `go_to_top` `go_to_bottom` |
| <kbd>Ctrl-f/b</kbd> | Scroll page down/up | `page_down` `page_up` |
| <kbd>Ctrl-d/u</kbd> | Scroll half page down/up | `half_page_down` `half_page_up` |
| <kbd>Ctrl-e/y</kbd> | Scroll down/up | `scroll_down` `scroll_up` |
| <kbd>H/M/L</kbd> | Select top/middle/bottom of the screen | `select_top` `select_middle` `select_bottom` |
| <kbd>Enter</kbd> | Show commit details<br>Apply search (if searching) | `confirm` |
| <kbd>Tab</kbd> | Open refs list | `ref_list_toggle` |
| <kbd>/</kbd> | Start search | `search` |
| <kbd>Esc</kbd> | Cancel search | `cancel` |
| <kbd>n/N</kbd> | Go to next/previous search match | `go_to_next` `go_to_previous` |
| <kbd>c/C</kbd> | Copy commit short/full hash | `short_copy` `full_copy` |

#### Commit Detail

Expand Down
1 change: 1 addition & 0 deletions assets/default-keybind.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ navigate_up = ["k", "up"]
navigate_down = ["j", "down"]
navigate_right = ["l", "right"]
navigate_left = ["h", "left"]
go_to_parent = ["alt-j", "alt-down"]

go_to_top = ["g"]
go_to_bottom = ["shift-g"]
Expand Down
1 change: 1 addition & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub enum UserEvent {
NavigateLeft,
GoToTop,
GoToBottom,
GoToParent,
ScrollUp,
ScrollDown,
PageUp,
Expand Down
1 change: 1 addition & 0 deletions src/view/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ fn build_lines(keybind: &KeyBind) -> (Vec<Line<'static>>, Vec<Line<'static>>) {
&[
(&[UserEvent::NavigateDown], "Move down"),
(&[UserEvent::NavigateUp], "Move up"),
(&[UserEvent::GoToParent], "Go to parent"),
(&[UserEvent::GoToTop], "Go to top"),
(&[UserEvent::GoToBottom], "Go to bottom"),
(&[UserEvent::PageDown], "Scroll page down"),
Expand Down
3 changes: 3 additions & 0 deletions src/view/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ impl<'a> ListView<'a> {
UserEvent::NavigateUp => {
self.as_mut_list_state().select_prev();
}
UserEvent::GoToParent => {
self.as_mut_list_state().select_parent();
}
UserEvent::GoToTop => {
self.as_mut_list_state().select_first();
}
Expand Down
17 changes: 17 additions & 0 deletions src/widget/commit_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ impl<'a> CommitListState<'a> {
}
}

pub fn select_parent(&mut self) {
let target_commit = self.selected_commit_parent_hash().clone();
while target_commit.as_str() != self.selected_commit_hash().as_str() {
self.select_next();
}
}

pub fn selected_commit_parent_hash(&self) -> &CommitHash {
let selected_commit_hash = self.selected_commit_hash();

self.commits[self.current_selected_index()]
.commit
.parent_commit_hashes
.first()
.unwrap_or(selected_commit_hash)
}

pub fn select_prev(&mut self) {
if self.selected > 0 {
self.selected -= 1;
Expand Down