Skip to content

Commit

Permalink
feat: move to parent section with alt+h
Browse files Browse the repository at this point in the history
  • Loading branch information
altsem committed Apr 21, 2024
1 parent 910eab1 commit 5d89ece
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ root.move_up_line = ["<ctrl+k>", "<ctrl+up>"]
root.move_down_line = ["<ctrl+j>", "<ctrl+down>"]
root.move_prev_section = ["<alt+k>", "<alt+up>"]
root.move_next_section = ["<alt+j>", "<alt+down>"]
root.move_parent_section = ["<alt+h>", "<alt+left>"]
root.half_page_up = ["<ctrl+u>"]
root.half_page_down = ["<ctrl+d>"]
root.show_refs = ["Y"]
Expand Down
15 changes: 15 additions & 0 deletions src/ops/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ impl OpTrait for MovePrevSection {
}
}

#[derive(Display)]
#[display(fmt = "Parent section")]
pub(crate) struct MoveParentSection;
impl OpTrait for MoveParentSection {
fn get_action(&self, _target: Option<&TargetData>) -> Option<Action> {
Some(Rc::new(|state, _term| {
let depth = state.screen().get_selected_item().depth.saturating_sub(1);
state
.screen_mut()
.select_previous(NavMode::Siblings { depth });
Ok(())
}))
}
}

#[derive(Display)]
#[display(fmt = "Half page up")]
pub(crate) struct HalfPageUp;
Expand Down
2 changes: 2 additions & 0 deletions src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub(crate) enum Op {
MoveDownLine,
MovePrevSection,
MoveNextSection,
MoveParentSection,
HalfPageUp,
HalfPageDown,

Expand All @@ -116,6 +117,7 @@ impl Op {
Op::MoveUpLine => Box::new(editor::MoveUpLine),
Op::MoveNextSection => Box::new(editor::MoveNextSection),
Op::MovePrevSection => Box::new(editor::MovePrevSection),
Op::MoveParentSection => Box::new(editor::MoveParentSection),
Op::HalfPageUp => Box::new(editor::HalfPageUp),
Op::HalfPageDown => Box::new(editor::HalfPageDown),

Expand Down
9 changes: 9 additions & 0 deletions src/tests/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ fn move_next_sibling() {
state.update(&mut ctx.term, &keys("<alt+j>")).unwrap();
insta::assert_snapshot!(ctx.redact_buffer());
}

#[test]
fn move_next_then_parent_section() {
let (mut ctx, mut state) = setup_scroll();
state
.update(&mut ctx.term, &keys("<alt+j><alt+h>"))
.unwrap();
insta::assert_snapshot!(ctx.redact_buffer());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: src/tests/editor.rs
expression: ctx.redact_buffer()
---
Unstaged changes (3) |
modified file-1 |
▌@@ -0,0 +1,20 @@ |
+line 1 (file-1) |
+line 2 (file-1) |
+line 3 (file-1) |
+line 4 (file-1) |
+line 5 (file-1) |
+line 6 (file-1) |
+line 7 (file-1) |
+line 8 (file-1) |
+line 9 (file-1) |
+line 10 (file-1) |
+line 11 (file-1) |
+line 12 (file-1) |
+line 13 (file-1) |
+line 14 (file-1) |
+line 15 (file-1) |
+line 16 (file-1) |
+line 17 (file-1) |
styles_hash: fc17643854723800
28 changes: 14 additions & 14 deletions src/tests/snapshots/gitu__tests__help_menu.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ expression: ctx.redact_buffer()
Recent commits |
|
|
|
────────────────────────────────────────────────────────────────────────────────|
Help Submenu |
Y Show refs b Branch |
<tab> Toggle section c Commit |
k/<up> Up f Fetch |
j/<down> Down h Help |
<ctrl+k>/<ctrl+up> Up line l Log |
<ctrl+j>/<ctrl+down> Down line F Pull |
<alt+k>/<alt+up> Prev section P Push |
<alt+j>/<alt+down> Next section r Rebase |
<ctrl+u> Half page up X Reset |
<ctrl+d> Half page down V Revert |
g Refresh z Stash |
Help Submenu |
Y Show refs b Branch |
<tab> Toggle section c Commit |
k/<up> Up f Fetch |
j/<down> Down h Help |
<ctrl+k>/<ctrl+up> Up line l Log |
<ctrl+j>/<ctrl+down> Down line F Pull |
<alt+k>/<alt+up> Prev section P Push |
<alt+j>/<alt+down> Next section r Rebase |
<alt+h>/<alt+left> Parent section X Reset |
<ctrl+u> Half page up V Revert |
<ctrl+d> Half page down z Stash |
g Refresh |
q/<esc> Quit/Close |
styles_hash: 86d28ec74971a2b3
styles_hash: 5a8c4080986bbe0d

0 comments on commit 5d89ece

Please sign in to comment.