Remove unused 'view' argument from open_editor
[tig] / tig.c
diff --git a/tig.c b/tig.c
index ac2aba0..620f14b 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -2143,11 +2143,12 @@ open_view(struct view *prev, enum request request, enum open_flags flags)
 }
 
 static void
-open_editor(struct view *view, char *file)
+open_editor(bool from_root, char *file)
 {
        char cmd[SIZEOF_STR];
        char file_sq[SIZEOF_STR];
        char *editor;
+       char *prefix = from_root ? opt_cdup : "";
 
        editor = getenv("GIT_EDITOR");
        if (!editor && *opt_editor)
@@ -2160,7 +2161,7 @@ open_editor(struct view *view, char *file)
                editor = "vi";
 
        if (sq_quote(file_sq, 0, file) < sizeof(file_sq) &&
-           string_format(cmd, "%s %s", editor, file_sq)) {
+           string_format(cmd, "%s %s%s", editor, prefix, file_sq)) {
                def_prog_mode();           /* save current tty modes */
                endwin();                  /* restore original tty modes */
                system(cmd);
@@ -3051,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))
@@ -3080,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;
 }
 
@@ -3309,7 +3319,7 @@ status_request(struct view *view, enum request request, struct line *line)
                if (!status)
                        return request;
 
-               open_editor(view, status->name);
+               open_editor(status->status != '?', status->name);
                break;
 
        case REQ_ENTER:
@@ -3543,7 +3553,7 @@ stage_request(struct view *view, enum request request, struct line *line)
                if (!stage_status.name[0])
                        return request;
 
-               open_editor(view, stage_status.name);
+               open_editor(stage_status.status != '?', stage_status.name);
                break;
 
        case REQ_ENTER: