Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ blame.code_line = { mods = "DIM" }

[bindings]
root.quit = ["q", "esc"]
root.refresh = ["g"]
root.refresh = ["g+r"]
root.toggle_section = ["tab"]
root.move_up = ["k", "up"]
root.move_down = ["j", "down"]
Expand All @@ -116,6 +116,8 @@ 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.move_top = ["g+g"]
root.move_bottom = ["G"]
root.show_refs = ["Y"]
root.show = ["enter"]
root.discard = ["K"]
Expand Down
28 changes: 28 additions & 0 deletions src/ops/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,31 @@ impl OpTrait for HalfPageDown {
"Half page down".into()
}
}

pub(crate) struct MoveTop;
impl OpTrait for MoveTop {
fn get_action(&self, _target: &ItemData) -> Option<Action> {
Some(Rc::new(|app, _term| {
app.screen_mut().move_cursor_to_top();
Ok(())
}))
}

fn display(&self, _state: &State) -> String {
"Top".into()
}
}

pub(crate) struct MoveBottom;
impl OpTrait for MoveBottom {
fn get_action(&self, _target: &ItemData) -> Option<Action> {
Some(Rc::new(|app, _term| {
app.screen_mut().move_cursor_to_bottom();
Ok(())
}))
}

fn display(&self, _state: &State) -> String {
"Bottom".into()
}
}
4 changes: 4 additions & 0 deletions src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ pub(crate) enum Op {
MovePrevSection,
MoveNextSection,
MoveParentSection,
MoveTop,
MoveBottom,
HalfPageUp,
HalfPageDown,

Expand Down Expand Up @@ -153,6 +155,8 @@ impl Op {
Op::MoveParentSection => Box::new(editor::MoveParentSection),
Op::HalfPageUp => Box::new(editor::HalfPageUp),
Op::HalfPageDown => Box::new(editor::HalfPageDown),
Op::MoveTop => Box::new(editor::MoveTop),
Op::MoveBottom => Box::new(editor::MoveBottom),
Op::Checkout => Box::new(branch::Checkout),
Op::CheckoutNewBranch => Box::new(branch::CheckoutNewBranch),
Op::Spinoff => Box::new(branch::Spinoff),
Expand Down
24 changes: 24 additions & 0 deletions src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,30 @@ impl Screen {
}
}

pub(crate) fn move_cursor_to_top(&mut self) {
if self.line_index.is_empty() {
return;
}
if let Some(first) = self.find_first_selectable() {
self.cursor = first;
self.scroll = 0;
}
}

pub(crate) fn move_cursor_to_bottom(&mut self) {
if self.line_index.is_empty() {
return;
}
if let Some(last) = self.find_last_selectable() {
self.cursor = last;
self.scroll_fit_end();
}
}

fn find_last_selectable(&self) -> Option<usize> {
(0..self.line_index.len()).rfind(|&line_i| !self.at_line(line_i).unselectable)
}

pub(crate) fn is_collapsed(&self, item: &Item) -> bool {
self.collapsed.contains(&item.id)
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn commit_instant_fixup() {
commit(&ctx.dir, "instant_fixup.txt", "mistake\n");
fs::write(ctx.dir.join("instant_fixup.txt"), "fixed\n").unwrap();
run(&ctx.dir, &["git", "add", "."]);
ctx.update(&mut state, keys("gjjjjjcF"));
ctx.update(&mut state, keys("grjjjjjcF"));

insta::assert_snapshot!(ctx.redact_buffer());
}
Expand All @@ -38,7 +38,7 @@ fn commit_instant_fixup_stashes_changes_and_keeps_empty() {
fs::write(ctx.dir.join("instant_fixup.txt"), "fixed\n").unwrap();
run(&ctx.dir, &["git", "add", "."]);
fs::write(ctx.dir.join("instant_fixup.txt"), "unstaged\n").unwrap();
ctx.update(&mut state, keys("gjjjjjjjjjcF"));
ctx.update(&mut state, keys("grjjjjjjjjjcF"));

insta::assert_snapshot!(ctx.redact_buffer());
}
Expand Down
12 changes: 6 additions & 6 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ fn hide_untracked() {
// Git expects "no|normal|all" here; "off" can error on some versions and break `git status`.
config.set_str("status.showUntrackedFiles", "no").unwrap();

ctx.update(&mut app, keys("g"));
ctx.update(&mut app, keys("gr"));
insta::assert_snapshot!(ctx.redact_buffer());
}

Expand Down Expand Up @@ -366,7 +366,7 @@ fn updated_externally() {

fs::write(ctx.dir.join("a"), "test\n").unwrap();

ctx.update(&mut app, keys("g"));
ctx.update(&mut app, keys("gr"));
insta::assert_snapshot!(ctx.redact_buffer());
}

Expand Down Expand Up @@ -443,7 +443,7 @@ fn crlf_diff() {

commit(&ctx.dir, "crlf.txt", "unchanged\r\nunchanged\r\n");
fs::write(ctx.dir.join("crlf.txt"), "unchanged\r\nchanged\r\n").unwrap();
ctx.update(&mut app, keys("g"));
ctx.update(&mut app, keys("gr"));

insta::assert_snapshot!(ctx.redact_buffer());
}
Expand All @@ -455,7 +455,7 @@ fn tab_diff() {

commit(&ctx.dir, "tab.txt", "this has no tab prefixed\n");
fs::write(ctx.dir.join("tab.txt"), "\tthis has a tab prefixed\n").unwrap();
ctx.update(&mut app, keys("g"));
ctx.update(&mut app, keys("gr"));

insta::assert_snapshot!(ctx.redact_buffer());
}
Expand All @@ -471,7 +471,7 @@ fn non_utf8_diff() {
b"File with invalid UTF-8: \xff\xfe\n",
)
.unwrap();
ctx.update(&mut app, keys("g"));
ctx.update(&mut app, keys("gr"));

insta::assert_snapshot!(ctx.redact_buffer());
}
Expand All @@ -486,7 +486,7 @@ fn ext_diff() {
run(&ctx.dir, &["git", "add", "-N", "unstaged.txt"]);
run(&ctx.dir, &["git", "add", "staged.txt"]);
run(&ctx.dir, &["git", "config", "diff.external", "/dev/null"]);
ctx.update(&mut app, keys("g"));
ctx.update(&mut app, keys("gr"));

insta::assert_snapshot!(ctx.redact_buffer());
}
Expand Down
15 changes: 8 additions & 7 deletions src/tests/snapshots/gitu__tests__help_menu.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: src/tests/mod.rs
assertion_line: 50
expression: ctx.redact_buffer()
---
▌On branch main |
Expand All @@ -16,10 +17,10 @@ expression: ctx.redact_buffer()
alt+k/alt+up Prev section m Merge |
alt+j/alt+down Next section M Remote |
alt+h/alt+left Parent section F Pull |
ctrl+u Half page up P Push |
ctrl+d Half page down r Rebase |
g Refresh X Reset |
q/esc Quit/Close V Revert |
A Cherry-pick |
z Stash |
styles_hash: f023ed50da817507
g+g Top P Push |
G Bottom r Rebase |
ctrl+u Half page up X Reset |
ctrl+d Half page down V Revert |
g+r Refresh A Cherry-pick |
q/esc Quit/Close z Stash |
styles_hash: d3bd90efdd7b7678
2 changes: 1 addition & 1 deletion src/ui/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ mod tests {
layout.text("<alt+h>/<alt+left> Parent section");
layout.text("<ctrl+u> Half page up");
layout.text("<ctrl+d> Half page down");
layout.text("g Refresh");
layout.text("g+r Refresh");
layout.text("q/<esc> Quit/Close");
});
layout.vertical(None, OPTS, |layout| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ j/<down> Down h/? Help K Discard
<alt+h>/<alt+left> Parent section r Rebase
<ctrl+u> Half page up X Reset
<ctrl+d> Half page down V Revert
g Refresh z Stash
g+r Refresh z Stash
q/<esc> Quit/Close
Loading