Skip to content

Commit

Permalink
Fix cursor behaviour during staging
Browse files Browse the repository at this point in the history
In the status view, when the `Changes to be committed` section is empty,
a line with `(no files)` is inserted. This line disappears when the fist
file is staged, this has to be taken into account for the cursor position.

Fixes jonas#842, jonas#1028
  • Loading branch information
koutcher committed May 15, 2022
1 parent a40f5b5 commit ff1ada9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Bug fixes:
- Fix search when view is loading.
- Use the full width for diffstat in the stage view.
- Improve escaping of variables in external commands.
- Fix cursor behaviour during staging. (#842, #1028)

tig-2.5.5
---------
Expand Down
20 changes: 14 additions & 6 deletions src/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

static char status_onbranch[SIZEOF_STR];
static bool show_untracked_only = false;
static bool no_files_staged;

void
open_status_view(struct view *prev, bool untracked_only, enum open_flags flags)
Expand Down Expand Up @@ -161,19 +162,23 @@ status_run(struct view *view, const char *argv[], char status, enum line_type ty

if (!view->line[view->lines - 1].data) {
add_line_nodata(view, LINE_STAT_NONE);
if (type == LINE_STAT_STAGED)
if (type == LINE_STAT_STAGED) {
watch_apply(&view->watch, WATCH_INDEX_STAGED_NO);
else if (type == LINE_STAT_UNSTAGED)
no_files_staged = true;
} else if (type == LINE_STAT_UNSTAGED) {
watch_apply(&view->watch, WATCH_INDEX_UNSTAGED_NO);
else if (type == LINE_STAT_UNTRACKED)
} else if (type == LINE_STAT_UNTRACKED) {
watch_apply(&view->watch, WATCH_INDEX_UNTRACKED_NO);
}
} else {
if (type == LINE_STAT_STAGED)
if (type == LINE_STAT_STAGED) {
watch_apply(&view->watch, WATCH_INDEX_STAGED_YES);
else if (type == LINE_STAT_UNSTAGED)
no_files_staged = false;
} else if (type == LINE_STAT_UNSTAGED) {
watch_apply(&view->watch, WATCH_INDEX_UNSTAGED_YES);
else if (type == LINE_STAT_UNTRACKED)
} else if (type == LINE_STAT_UNTRACKED) {
watch_apply(&view->watch, WATCH_INDEX_UNTRACKED_YES);
}
}

io_done(&io);
Expand Down Expand Up @@ -644,6 +649,9 @@ status_update(struct view *view)
return false;
}

if (line->type != LINE_STAT_STAGED && !no_files_staged)
view->pos.lineno += 1;

return true;
}

Expand Down

0 comments on commit ff1ada9

Please sign in to comment.