tig
tig copied to clipboard
WIP improved context-sensitive view-blob
I would like to improve the sensitivity of some tig actions to their context.
This is expressed here as three TODO tests which call view-blob from the diff view.
Tig already adopts the model of context-sensitive action here, but it depends on the cursor directly touching a line which it can associate to a blob. When that is not true, tig opens the last blob it can remember, or opens the file finder.
Neither of those is likely to match user expectations. But when viewing a diff, the cursor is always either on a blob-associated line, or before some blob-associated line. So I propose that the simplest intuitive context-sensitive view-blob is
- view this line's blob, or failing that
- scan forward by lines and view the next associated blob
This makes sense and sounds like it will bring view-blob more in line with how the edit action works. However it is a bit hard to understand the behavior from only looking at the todo tests.
I got as far as the following, which passes the included todos, but fails many others.
diff --git a/src/diff.c b/src/diff.c
index 583f1e0e0..29e002691 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -624,16 +624,16 @@ diff_get_pathname(struct view *view, struct line *line)
int i;
header = find_prev_line_by_type(view, line, LINE_DIFF_HEADER);
- if (!header)
- return NULL;
- for (i = 0; i < ARRAY_SIZE(prefixes); i++) {
- dst = strstr(box_text(header), prefixes[i]);
- if (dst)
- return dst + strlen(prefixes[i]);
- }
+ if (header)
+ for (i = 0; i < ARRAY_SIZE(prefixes); i++) {
+ dst = strstr(box_text(header), prefixes[i]);
+ if (dst)
+ return dst + strlen(prefixes[i]);
+ }
+
+ header = find_next_line_by_type(view, header ? header : line, LINE_DIFF_ADD_FILE);
- header = find_next_line_by_type(view, header, LINE_DIFF_ADD_FILE);
if (!header)
return NULL;