From 11238ef7fb35ab769cf673c1f90b99bc634c7d13 Mon Sep 17 00:00:00 2001 From: Thomas Koutcher Date: Thu, 2 Jun 2022 20:29:59 +0200 Subject: [PATCH] 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 --- include/tig/view.h | 2 ++ src/stage.c | 4 +++- src/tig.c | 32 -------------------------------- src/view.c | 32 ++++++++++++++++++++++++++++++++ test/status/file-name-test | 21 ++++++++++++++++++++- 5 files changed, 57 insertions(+), 34 deletions(-) diff --git a/include/tig/view.h b/include/tig/view.h index 6b7bf6803..794530c1c 100644 --- a/include/tig/view.h +++ b/include/tig/view.h @@ -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 */ diff --git a/src/stage.c b/src/stage.c index 733f4e053..d4e9b26d0 100644 --- a/src/stage.c +++ b/src/stage.c @@ -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); diff --git a/src/tig.c b/src/tig.c index cc6201677..8d3ed2221 100644 --- a/src/tig.c +++ b/src/tig.c @@ -60,38 +60,6 @@ #include #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 */ diff --git a/src/view.c b/src/view.c index bc2e2020a..8498e8cee 100644 --- a/src/view.c +++ b/src/view.c @@ -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. */ diff --git a/test/status/file-name-test b/test/status/file-name-test index 1c4702e65..a0a730bfb 100755 --- a/test/status/file-name-test +++ b/test/status/file-name-test @@ -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 @@ -104,6 +106,23 @@ Untracked files: |ø EOF assert_equals 'status-with-file-2.screen' <