Skip to content

Commit

Permalink
Support %(text) in all views with a text column
Browse files Browse the repository at this point in the history
PR #457 implemented %(text) for the pager view only. Extend %(text) support
to the blame, blob, grep and log views.

Fixes #1275
  • Loading branch information
koutcher committed Oct 29, 2023
1 parent 707c8cd commit ee246ab
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ blame_select(struct view *view, struct line *line)
{
struct blame *blame = line->data;
struct blame_commit *commit = blame->commit;
const char *text = blame->text;

if (!commit)
return;
Expand All @@ -481,6 +482,7 @@ blame_select(struct view *view, struct line *line)
view->env->file_old[0] = '\0';

view->env->lineno = view->pos.lineno + 1;
string_ncopy(view->env->text, text, strlen(text));
}

static struct view_ops blame_ops = {
Expand Down
2 changes: 2 additions & 0 deletions src/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ static void
blob_select(struct view *view, struct line *line)
{
struct blob_state *state = view->private;
const char *text = box_text(line);

if (state->file)
string_format(view->env->file, "%s", state->file);
view->env->lineno = view->pos.lineno + 1;
string_ncopy(view->env->text, text, strlen(text));
}

static enum request
Expand Down
2 changes: 2 additions & 0 deletions src/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ static void
grep_select(struct view *view, struct line *line)
{
struct grep_line *grep = grep_get_line(line);
const char *text = grep->text;

if (!*grep->file)
return;
view->env->ref[0] = 0;
string_ncopy(view->env->file, grep->file, strlen(grep->file));
string_ncopy(view->ref, grep->file, strlen(grep->file));
view->env->lineno = grep->lineno + 1;
string_ncopy(view->env->text, text, strlen(text));
}

static const char *grep_args[] = {
Expand Down
2 changes: 2 additions & 0 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ log_select(struct view *view, struct line *line)
{
struct log_state *state = view->private;
int last_lineno = state->last_lineno;
const char *text = box_text(line);

if (!last_lineno || abs(last_lineno - line->lineno) > 1
|| (state->last_type == LINE_COMMIT && last_lineno > line->lineno)) {
Expand All @@ -56,6 +57,7 @@ log_select(struct view *view, struct line *line)
if (line->type == LINE_COMMIT && !view_has_flags(view, VIEW_NO_REF))
log_copy_rev(view, line);
string_copy_rev(view->env->commit, view->ref);
string_ncopy(view->env->text, text, strlen(text));
state->last_lineno = line->lineno;
state->last_type = line->type;
}
Expand Down

0 comments on commit ee246ab

Please sign in to comment.