Skip to content

Commit

Permalink
Merge branch 'fix-quickview-redraw'
Browse files Browse the repository at this point in the history
Fix quickview not being updated on file replacement, meaning that
cursor position on the screen remained the same, but file under the
cursor has changed.

Thanks to mrajner.
  • Loading branch information
xaizek committed Jun 12, 2019
2 parents a728ab4 + 982a229 commit bde146b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
1 change: 1 addition & 0 deletions THANKS
Expand Up @@ -122,6 +122,7 @@ Milan Svoboda (tex)
Miles (pkordy)
mini-turtle
Miodrag Tokić (loonies)
mrajner
mvucBmM0
mwgkgk
nicodebo
Expand Down
2 changes: 2 additions & 0 deletions src/filelist.c
Expand Up @@ -293,6 +293,8 @@ flist_free_view(view_t *view)
flist_free_cache(view, &view->left_column);
flist_free_cache(view, &view->right_column);

update_string(&view->last_curr_file, NULL);

free_string_array(view->saved_selection, view->nsaved_selection);
view->nsaved_selection = 0;
view->saved_selection = NULL;
Expand Down
78 changes: 45 additions & 33 deletions src/ui/fileview.c
Expand Up @@ -142,6 +142,8 @@ static size_t calculate_columns_count(struct view_t *view);
static size_t get_max_filename_width(const view_t *view);
static size_t get_filename_width(const view_t *view, int i);
static size_t get_filetype_decoration_width(const dir_entry_t *entry);
static int cache_cursor_pos(view_t *view);
static void invalidate_cursor_pos_cache(view_t *view);
static void position_hardware_cursor(view_t *view);
static int move_curr_line(view_t *view);
static void reset_view_columns(view_t *view);
Expand Down Expand Up @@ -816,29 +818,10 @@ redraw_current_view(void)
void
fview_cursor_redraw(view_t *view)
{
if(view != curr_view)
{
if(move_curr_line(view))
{
draw_dir_list(view);
}
fview_draw_inactive_cursor(view);
return;
}

if(move_curr_line(view))
{
draw_dir_list(view);
return;
}

if(!ui_view_displays_columns(view))
{
/* Inactive cell in ls-like view usually takes less space than an active
* one. Need to clear the cell before drawing over it. */
redraw_cell(view, view->top_line, view->curr_line, 0);
}
redraw_cell(view, view->top_line, view->curr_line, 1);
// fview_cursor_redraw() is also called in situations when file list has
// changed, so just let fview_position_updated() deal with it. With a cache
// of last position, it should be fine.
fview_position_updated(view);
}

void
Expand All @@ -849,7 +832,7 @@ fview_draw_inactive_cursor(view_t *view)

/* Reset last seen position on drawing inactive cursor or an active one won't
* be drawn next time. */
view->last_seen_pos = -1;
invalidate_cursor_pos_cache(view);

if(!ui_view_displays_columns(view))
{
Expand Down Expand Up @@ -1711,7 +1694,7 @@ fview_list_updated(view_t *view)
/* Invalidate maximum file name widths cache. */
view->max_filename_width = 0;
/* Even if position will remain the same, we might need to redraw it. */
view->last_seen_pos = -1;
invalidate_cursor_pos_cache(view);
}

/* Evaluates number of columns in the view. Returns the number. */
Expand Down Expand Up @@ -1781,8 +1764,6 @@ fview_position_updated(view_t *view)
const int old_top = view->top_line;
const int old_curr = view->curr_line;

int redraw;

if(view->curr_line > view->list_rows - 1)
{
view->curr_line = view->list_rows - 1;
Expand All @@ -1795,7 +1776,7 @@ fview_position_updated(view_t *view)

if(view == other_view)
{
view->last_seen_pos = -1;
invalidate_cursor_pos_cache(view);
if(move_curr_line(view))
{
draw_dir_list(view);
Expand All @@ -1808,15 +1789,17 @@ fview_position_updated(view_t *view)
return;
}

redraw = move_curr_line(view);

if(curr_stats.load_stage < 2 ||
(!redraw && view->list_pos == view->last_seen_pos))
if(curr_stats.load_stage < 2)
{
return;
}

view->last_seen_pos = view->list_pos;
int redraw = move_curr_line(view);
int up_to_date = cache_cursor_pos(view);
if(!redraw && up_to_date)
{
return;
}

if(redraw)
{
Expand Down Expand Up @@ -1847,6 +1830,35 @@ fview_position_updated(view_t *view)
}
}

/* Compares current cursor position against previously cached one and updates
* the cache if necessary. Returns non-zero if cache is up to date, otherwise
* zero is returned. */
static int
cache_cursor_pos(view_t *view)
{
char path[PATH_MAX + 1];
get_current_full_path(view, sizeof(path), path);

if(view->list_pos == view->last_seen_pos &&
view->curr_line == view->last_curr_line &&
strcmp(view->last_curr_file, path) == 0)
{
return 1;
}

view->last_seen_pos = view->list_pos;
view->last_curr_line = view->curr_line;
replace_string(&view->last_curr_file, path);
return 0;
}

/* Invalidates cache of current cursor position for the specified view. */
static void
invalidate_cursor_pos_cache(view_t *view)
{
view->last_seen_pos = -1;
}

/* Moves hardware cursor to the beginning of the name of current entry. */
static void
position_hardware_cursor(view_t *view)
Expand Down
6 changes: 5 additions & 1 deletion src/ui/ui.h
Expand Up @@ -366,14 +366,18 @@ struct view_t
int curr_line; /* current line # of the window */
int top_line; /* # of the list position that is the top line in window */
int list_pos; /* actual position in the file list */
int last_seen_pos; /* Last position that was displayed on the screen. */
int list_rows; /* size of the file list */
int window_rows; /* Number of rows in the window. */
int window_cols; /* Number of columns in the window. */
int filtered; /* number of files filtered out and not shown in list */
int selected_files; /* Number of currently selected files. */
dir_entry_t *dir_entry; /* Must be handled via dynarray unit. */

/* Last position that was displayed on the screen. */
char *last_curr_file; /* To account for file replacement. */
int last_seen_pos; /* To account for movement. */
int last_curr_line; /* To account for scrolling. */

int nsaved_selection; /* Number of items in saved_selection. */
char **saved_selection; /* Names of selected files. */

Expand Down

0 comments on commit bde146b

Please sign in to comment.