Skip to content

Commit

Permalink
diff: support edit from diff stat
Browse files Browse the repository at this point in the history
When selecting a diff stat, Tig assigns the %(file) and %(lineno)
variables. So reuse them when the user requests the editor, instead of
trying (and failing) to find the corresponding filename.

Refs #404

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
  • Loading branch information
vivien committed Apr 26, 2015
1 parent 99e4b4a commit 4001220
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/diff.c
Expand Up @@ -463,16 +463,24 @@ diff_get_pathname(struct view *view, struct line *line)
enum request
diff_common_edit(struct view *view, enum request request, struct line *line)
{
const char *file = diff_get_pathname(view, line);
const char *file;
char path[SIZEOF_STR];
bool has_path = file && string_format(path, "%s%s", repo.cdup, file);
unsigned int lineno;

if (line->type == LINE_DIFF_STAT) {
file = view->env->file;
lineno = view->env->lineno;
} else {
file = diff_get_pathname(view, line);
lineno = diff_get_lineno(view, line);
}

if (has_path && access(path, R_OK)) {
if (file && string_format(path, "%s%s", repo.cdup, file) && access(path, R_OK)) {
report("Failed to open file: %s", file);
return REQ_NONE;
}

open_editor(file, diff_get_lineno(view, line));
open_editor(file, lineno);
return REQ_NONE;
}

Expand Down

0 comments on commit 4001220

Please sign in to comment.