Skip to content

Commit 11238ef

Browse files
committed
Automatically show next diff in the status view
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 #413, closes #469
1 parent 4a405bf commit 11238ef

File tree

5 files changed

+57
-34
lines changed

5 files changed

+57
-34
lines changed

include/tig/view.h

+2
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ find_line_by_type(struct view *view, struct line *line, enum line_type type, int
329329
#define get_view_color(view, type) get_line_color((view)->keymap->name, type)
330330
#define get_view_attr(view, type) get_line_attr((view)->keymap->name, type)
331331

332+
enum request view_request(struct view *view, enum request request);
333+
332334
/*
333335
* Incremental updating
334336
*/

src/stage.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,9 @@ stage_request(struct view *view, enum request request, struct line *line)
680680
* stage view if it doesn't. */
681681
if (view->parent && !stage_exists(view, &stage_status, stage_line_type)) {
682682
stage_line_type = 0;
683-
return REQ_VIEW_CLOSE;
683+
return view->parent == &status_view
684+
? view_request(view->parent, REQ_ENTER)
685+
: REQ_VIEW_CLOSE;
684686
}
685687

686688
refresh_view(view);

src/tig.c

-32
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,6 @@
6060
#include <pcre.h>
6161
#endif
6262

63-
static bool
64-
forward_request_to_child(struct view *child, enum request request)
65-
{
66-
return displayed_views() == 2 && view_is_displayed(child) &&
67-
!strcmp(child->vid, child->ops->id);
68-
}
69-
70-
static enum request
71-
view_request(struct view *view, enum request request)
72-
{
73-
if (!view || !view->lines)
74-
return request;
75-
76-
if (request == REQ_ENTER && view == display[0] &&
77-
!opt_focus_child && opt_send_child_enter &&
78-
view_has_flags(view, VIEW_SEND_CHILD_ENTER)) {
79-
struct view *child = display[1];
80-
81-
if (forward_request_to_child(child, request)) {
82-
view_request(child, request);
83-
return REQ_NONE;
84-
}
85-
}
86-
87-
if (request == REQ_REFRESH && !view_can_refresh(view)) {
88-
report("This view can not be refreshed");
89-
return REQ_NONE;
90-
}
91-
92-
return view->ops->request(view, request, &view->line[view->pos.lineno]);
93-
}
94-
9563
/*
9664
* Option management
9765
*/

src/view.c

+32
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,38 @@ find_line_by_type(struct view *view, struct line *line, enum line_type type, int
15961596
return NULL;
15971597
}
15981598

1599+
static inline bool
1600+
forward_request_to_child(struct view *child, enum request request)
1601+
{
1602+
return displayed_views() == 2 && view_is_displayed(child) &&
1603+
!strcmp(child->vid, child->ops->id);
1604+
}
1605+
1606+
enum request
1607+
view_request(struct view *view, enum request request)
1608+
{
1609+
if (!view || !view->lines)
1610+
return request;
1611+
1612+
if (request == REQ_ENTER && view == display[0] &&
1613+
!opt_focus_child && opt_send_child_enter &&
1614+
view_has_flags(view, VIEW_SEND_CHILD_ENTER)) {
1615+
struct view *child = display[1];
1616+
1617+
if (forward_request_to_child(child, request)) {
1618+
view_request(child, request);
1619+
return REQ_NONE;
1620+
}
1621+
}
1622+
1623+
if (request == REQ_REFRESH && !view_can_refresh(view)) {
1624+
report("This view can not be refreshed");
1625+
return REQ_NONE;
1626+
}
1627+
1628+
return view->ops->request(view, request, &view->line[view->pos.lineno]);
1629+
}
1630+
15991631
/*
16001632
* Line utilities.
16011633
*/

test/status/file-name-test

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ steps '
1919
:enter
2020
:save-display status-with-file-1.screen
2121
:status-update
22+
:save-display status-with-file-2.screen
23+
:view-close
2224
2325
:7
2426
:status-update
2527
2628
:9
2729
:enter
28-
:save-display status-with-file-2.screen
30+
:save-display status-with-file-3.screen
2931
'
3032

3133
git_init
@@ -104,6 +106,23 @@ Untracked files: |ø
104106
EOF
105107

106108
assert_equals 'status-with-file-2.screen' <<EOF
109+
Initial commit |我
110+
Changes to be committed: |树
111+
A a |漢
112+
Changes not staged for commit: |
113+
(no files) |
114+
Untracked files: |
115+
? 0 |
116+
? as测试asd |
117+
? øå |
118+
? 可愛いコー特集 |
119+
|
120+
|
121+
|
122+
[status] Press u to stage 'as测试asd' for addition 100%|[stage] Untracked file as测试asd - line 1 of 3 100%
123+
EOF
124+
125+
assert_equals 'status-with-file-3.screen' <<EOF
107126
Initial commit |
108127
Changes to be committed: |
109128
A 0 |

0 commit comments

Comments
 (0)