jonas / tig

Text-mode interface for git
https://jonas.github.io/tig/
GNU General Public License v2.0
12.29k stars 604 forks source link

Allow to go to stage view without Enter #1284

Closed krobelus closed 5 months ago

krobelus commented 1 year ago

After selecting unstaged or staged changes in main or status view and pressing "c" to go to stage view, we fail with this error

No stage content, press s to open the status view and choose file

We can work around this by pressing Enter before "c". This extra key press is really not necessary because the intent is clear. Let's make view-stage (and view-diff) go to the stage view straight away.

Note: "d" already worked this way but only in the main view, I'm not sure why.

The implementation needs to differentiate between "stat headers" like "Changes to be committed" and status lines that actually contain a file. For stat headers we show all files so we must be careful not to include a file filter. For untracked files, we show a blob so there is no natural way of showing all untracked files. Keep the above behavior for the untracked stat header.

koutcher commented 10 months ago

Thanks @krobelus, but that's quite a lot of changes. In the spirit of what jonas did for "d" in the main view, couldn't we do more simply

diff --git a/src/main.c b/src/main.c
index 2401295b..05145955 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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, flags);
+               else
+                       return request;
+               break;
+
        case REQ_REFRESH:
                load_refs(true);
                refresh_view(view);
diff --git a/src/status.c b/src/status.c
index 0855dc34..7b476550 100644
--- a/src/status.c
+++ b/src/status.c
@@ -752,6 +752,15 @@ status_request(struct view *view, enum request request, struct line *line)
                        view->env->ref[0] = 0;
                return request;

+       case REQ_VIEW_STAGE:
+               if ((line->type == LINE_STAT_STAGED
+                    || line->type == LINE_STAT_UNSTAGED
+                    || line->type == LINE_STAT_UNTRACKED) && status && status->status)
+                       open_stage_view(view, status, line->type, view_is_displayed(view) ? OPEN_SPLIT : OPEN_DEFAULT);
+               else
+                       return request;
+               break;
+
        case REQ_ENTER:
                /* After returning the status view has been split to
                 * show the stage view. No further reloading is
krobelus commented 10 months ago

Interesting. This doesn't work when running :view-stage on individual files but maybe there is a way to add it to this approach

koutcher commented 8 months ago

Actually, in the status view, the result is better with just:

diff --git a/src/status.c b/src/status.c
index dd8c2afa..c9cfb684 100644
--- a/src/status.c
+++ b/src/status.c
@@ -756,6 +756,7 @@ status_request(struct view *view, enum request request, struct line *line)
                        view->env->ref[0] = 0;
                return request;

+       case REQ_VIEW_STAGE:
        case REQ_ENTER:
                /* After returning the status view has been split to
                 * show the stage view. No further reloading is
krobelus commented 5 months ago

Thanks, that works as expected. I had forgotten to test it