X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/tig/blobdiff_plain/7d31b0590bb4ae3f6a06d95e81ae54f13eebc632..12e8c2be5c217f1be8bfd48cc9723fc696b0fbf6:/tig.c diff --git a/tig.c b/tig.c index 3811a22..24f84d4 100644 --- a/tig.c +++ b/tig.c @@ -3052,12 +3052,14 @@ status_open(struct view *view) struct stat statbuf; char exclude[SIZEOF_STR]; char cmd[SIZEOF_STR]; + unsigned long prev_lineno = view->lineno; size_t i; + for (i = 0; i < view->lines; i++) free(view->line[i].data); free(view->line); - view->lines = view->line_size = 0; + view->lines = view->line_size = view->lineno = 0; view->line = NULL; if (!realloc_lines(view, view->line_size + 6)) @@ -3081,6 +3083,13 @@ status_open(struct view *view) !status_run(view, cmd, FALSE, LINE_STAT_UNTRACKED)) return FALSE; + /* If all went well restore the previous line number to stay in + * the context. */ + if (prev_lineno < view->lines) + view->lineno = prev_lineno; + else + view->lineno = view->lines - 1; + return TRUE; }