Skip to content

Commit

Permalink
Keep cursor position when toggling file-filter in the main view
Browse files Browse the repository at this point in the history
  • Loading branch information
koutcher committed May 30, 2024
1 parent 2a8ef0f commit c96dd26
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ master
Improvements:

- Open the blob corresponding to the diff line. (#1334)
- Keep cursor position when toggling file-filter in the main view.

tig-2.5.10
----------
Expand Down
8 changes: 6 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ main_add_commit(struct view *view, enum line_type type, struct commit *template,

view_column_info_update(view, line);

if ((opt_start_on_head && is_head_commit(commit->id)) ||
(view->env->goto_id[0] && !strncmp(view->env->goto_id, commit->id, SIZEOF_REV - 1)))
if (view->env->goto_id[0] && !strncmp(view->env->goto_id, commit->id, SIZEOF_REV - 1)) {
select_view_line(view, line->lineno + 1);
view->env->goto_id[0] = 0;
} else if (opt_start_on_head && is_head_commit(commit->id)) {
select_view_line(view, line->lineno + 1);
opt_start_on_head = false;
}

return commit;
}
Expand Down
9 changes: 7 additions & 2 deletions src/prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ readline_init(void)
/* Allow conditional parsing of the ~/.inputrc file. */
rl_readline_name = "tig";

/* Word break caracters (we removed '(' to match variables) */
/* Word break characters (we removed '(' to match variables) */
rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{";

/* Custom display function */
Expand Down Expand Up @@ -872,8 +872,13 @@ prompt_toggle(struct view *view, const char *argv[], enum view_flag *flags)
}

toggle = find_option_info(option_toggles, ARRAY_SIZE(option_toggles), "", option);
if (toggle)
if (toggle) {
if (!strcmp(toggle->name, "file_filter") &&
view_has_flags(view, VIEW_FILE_FILTER) &&
view_has_flags(view, VIEW_LOG_LIKE))
string_copy_rev(view->env->goto_id, view->env->commit);
return prompt_toggle_option(view, argv, "", toggle, flags);
}

for (column = view->columns; column; column = column->next) {
toggle = find_column_option_info(column->type, &column->opt, option, &template, &column_name);
Expand Down

0 comments on commit c96dd26

Please sign in to comment.