Skip to content

Commit

Permalink
Allow :back to work across separate blame views (#1127)
Browse files Browse the repository at this point in the history
* stop clearing the history state when entering the blame view

* push a blame view history state before entering the diff view

* stop failing when trying to push an identical history state

Closes #1123
  • Loading branch information
koutcher committed Oct 4, 2021
1 parent 0b607c4 commit 0d47854
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ blame_open(struct view *view, enum open_flags flags)
free(blame->commit);
}

if (!(flags & OPEN_RELOAD))
reset_view_history(&blame_view_history);
string_copy_rev(state->history_state.id, view->env->ref);
state->history_state.filename = get_path(view->env->file);
if (!state->history_state.filename)
Expand Down Expand Up @@ -455,6 +453,8 @@ blame_request(struct view *view, enum request request, struct line *line)
enum open_flags flags = view_is_displayed(view) ? OPEN_SPLIT : OPEN_DEFAULT;
struct blame *blame = line->data;
struct view *diff = &diff_view;
struct blame_state *state = view->private;
struct blame_history_state *history_state = &state->history_state;

switch (request) {
case REQ_VIEW_BLAME:
Expand All @@ -476,6 +476,11 @@ blame_request(struct view *view, enum request request, struct line *line)
!strcmp(blame->commit->id, diff->ref))
break;

if (!push_view_history_state(&blame_view_history, &view->pos, history_state)) {
report("Failed to save current view state");
break;
}

if (string_rev_is_null(blame->commit->id)) {
const char *diff_parent_argv[] = {
GIT_DIFF_BLAME(encoding_arg,
Expand Down
2 changes: 1 addition & 1 deletion src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ push_view_history_state(struct view_history *history, struct position *position,

if (state && data && history->state_alloc &&
!memcmp(state->data, data, history->state_alloc))
return NULL;
return state;

state = calloc(1, sizeof(*state) + history->state_alloc);
if (!state)
Expand Down

0 comments on commit 0d47854

Please sign in to comment.