Skip to content

Commit

Permalink
Automatically show next diff in the status view
Browse files Browse the repository at this point in the history
Move view_request() to view.c where it belongs and, when changing a file
status in a split stage view spawned from the status view, use it to
simulate pressing the Enter key in the parent view to display the next
diff.

Note: the behaviour is similar to that of the Up and Down keys, the
action has to be performed from the child view.

Closes jonas#413, closes jonas#469
  • Loading branch information
koutcher committed Dec 29, 2022
1 parent 4a405bf commit 11238ef
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 34 deletions.
2 changes: 2 additions & 0 deletions include/tig/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ find_line_by_type(struct view *view, struct line *line, enum line_type type, int
#define get_view_color(view, type) get_line_color((view)->keymap->name, type)
#define get_view_attr(view, type) get_line_attr((view)->keymap->name, type)

enum request view_request(struct view *view, enum request request);

/*
* Incremental updating
*/
Expand Down
4 changes: 3 additions & 1 deletion src/stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,9 @@ stage_request(struct view *view, enum request request, struct line *line)
* stage view if it doesn't. */
if (view->parent && !stage_exists(view, &stage_status, stage_line_type)) {
stage_line_type = 0;
return REQ_VIEW_CLOSE;
return view->parent == &status_view
? view_request(view->parent, REQ_ENTER)
: REQ_VIEW_CLOSE;
}

refresh_view(view);
Expand Down
32 changes: 0 additions & 32 deletions src/tig.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,6 @@
#include <pcre.h>
#endif

static bool
forward_request_to_child(struct view *child, enum request request)
{
return displayed_views() == 2 && view_is_displayed(child) &&
!strcmp(child->vid, child->ops->id);
}

static enum request
view_request(struct view *view, enum request request)
{
if (!view || !view->lines)
return request;

if (request == REQ_ENTER && view == display[0] &&
!opt_focus_child && opt_send_child_enter &&
view_has_flags(view, VIEW_SEND_CHILD_ENTER)) {
struct view *child = display[1];

if (forward_request_to_child(child, request)) {
view_request(child, request);
return REQ_NONE;
}
}

if (request == REQ_REFRESH && !view_can_refresh(view)) {
report("This view can not be refreshed");
return REQ_NONE;
}

return view->ops->request(view, request, &view->line[view->pos.lineno]);
}

/*
* Option management
*/
Expand Down
32 changes: 32 additions & 0 deletions src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,38 @@ find_line_by_type(struct view *view, struct line *line, enum line_type type, int
return NULL;
}

static inline bool
forward_request_to_child(struct view *child, enum request request)
{
return displayed_views() == 2 && view_is_displayed(child) &&
!strcmp(child->vid, child->ops->id);
}

enum request
view_request(struct view *view, enum request request)
{
if (!view || !view->lines)
return request;

if (request == REQ_ENTER && view == display[0] &&
!opt_focus_child && opt_send_child_enter &&
view_has_flags(view, VIEW_SEND_CHILD_ENTER)) {
struct view *child = display[1];

if (forward_request_to_child(child, request)) {
view_request(child, request);
return REQ_NONE;
}
}

if (request == REQ_REFRESH && !view_can_refresh(view)) {
report("This view can not be refreshed");
return REQ_NONE;
}

return view->ops->request(view, request, &view->line[view->pos.lineno]);
}

/*
* Line utilities.
*/
Expand Down
21 changes: 20 additions & 1 deletion test/status/file-name-test
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ steps '
:enter
:save-display status-with-file-1.screen
:status-update
:save-display status-with-file-2.screen
:view-close
:7
:status-update
:9
:enter
:save-display status-with-file-2.screen
:save-display status-with-file-3.screen
'

git_init
Expand Down Expand Up @@ -104,6 +106,23 @@ Untracked files: |ø
EOF

assert_equals 'status-with-file-2.screen' <<EOF
Initial commit |我
Changes to be committed: |树
A a |漢
Changes not staged for commit: |
(no files) |
Untracked files: |
? 0 |
? as测试asd |
? øå |
? 可愛いコー特集 |
|
|
|
[status] Press u to stage 'as测试asd' for addition 100%|[stage] Untracked file as测试asd - line 1 of 3 100%
EOF

assert_equals 'status-with-file-3.screen' <<EOF
Initial commit |
Changes to be committed: |
A 0 |
Expand Down

0 comments on commit 11238ef

Please sign in to comment.