Skip to content

Commit

Permalink
Allow to go to stage view without Enter
Browse files Browse the repository at this point in the history
Simplified version of PR #1284. Test is from the original PR.

Closes #1284

Original-patch-by: Johannes Altmanninger <aclopte@gmail.com>
  • Loading branch information
koutcher committed Jan 20, 2024
1 parent f523fa4 commit e2f1af4
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ main_request(struct view *view, enum request request, struct line *line)
open_diff_view(view, flags);
break;

case REQ_VIEW_STAGE:
if (line->type == LINE_STAT_UNSTAGED
|| line->type == LINE_STAT_STAGED)
open_stage_view(view, NULL, line->type, OPEN_DEFAULT);
else
return request;
break;

case REQ_REFRESH:
load_refs(true);
refresh_view(view);
Expand Down
8 changes: 5 additions & 3 deletions src/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,9 @@ status_get_column_data(struct view *view, const struct line *line, struct view_c
}

static enum request
status_enter(struct view *view, struct line *line)
status_enter(struct view *view, struct line *line, enum open_flags flags)
{
struct status *status = line->data;
enum open_flags flags = view_is_displayed(view) ? OPEN_SPLIT : OPEN_DEFAULT;

if (line->type == LINE_STAT_NONE ||
(!status && line[1].type == LINE_STAT_NONE)) {
Expand Down Expand Up @@ -760,7 +759,10 @@ status_request(struct view *view, enum request request, struct line *line)
/* After returning the status view has been split to
* show the stage view. No further reloading is
* necessary. */
return status_enter(view, line);
return status_enter(view, line, OPEN_SPLIT);

case REQ_VIEW_STAGE:
return status_enter(view, line, OPEN_DEFAULT);

case REQ_REFRESH:
/* Load the current branch information and then the view. */
Expand Down
56 changes: 56 additions & 0 deletions test/stage/default-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@ export LINES=20
steps '
:save-display status.screen
:2
:view-stage
:save-display staged-changes-shortcut.screen
:view-close
:5
:view-stage
:save-display unstaged-changes-shortcut.screen
:view-close
:view-main
:1
:view-stage
:save-display unstaged-changes-shortcut-from-main.screen
:view-close
:2
:view-stage
:save-display staged-changes-shortcut-from-main.screen
:view-close
:view-close
:4
:view-stage
:save-display staged-changes-for-a-shortcut.screen
:view-close
:2
:enter
:maximize
Expand Down Expand Up @@ -68,6 +97,33 @@ Untracked files:
[status] Nothing to update 100%
EOF

assert_equals 'staged-changes.screen' < 'staged-changes-shortcut.screen'
assert_equals 'unstaged-changes.screen' < 'unstaged-changes-shortcut.screen'
assert_equals 'staged-changes.screen' < 'staged-changes-shortcut-from-main.screen'
assert_equals 'unstaged-changes.screen' < 'unstaged-changes-shortcut-from-main.screen'

assert_equals 'staged-changes-for-a-shortcut.screen' <<EOF
a | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/a b/a
index 12d1d9e..0a4a332 100644
--- a/a
+++ b/a
@@ -1,4 +1,4 @@
-a
+a CHANGED
1
2
3
@@ -6,6 +6,4 @@ a
5
6
7
-8
[stage] Press '<Enter>' to jump to file diff - line 1 of 23 78%
EOF

assert_equals 'staged-changes.screen' <<EOF
.j | 6 ++----
a | 6 ++----
Expand Down

0 comments on commit e2f1af4

Please sign in to comment.