xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 2624fe6071ea74c9c863cb718cb11bb947c6963e

Avoid views scrolling unnecessarily
That happened in response to file-system changes that add or remove
files before the first visible line.

Thanks to justpretending2.

Closes <https://github.com/vifm/vifm/issues/1027>.
Author: xaizek
Author date (UTC): 2026-10-04 13:09
Committer name: xaizek
Committer date (UTC): 2026-10-18 13:19
Parent(s): c6007343c5ef29d783d67cd6f2987a32ea12b5ef
Signing key: 99DC5E4DB05F6BE2
Tree: 2898cc87371fd4a245675f7918c51c4451fca42e
File Lines added Lines deleted
ChangeLog 4 0
src/filelist.c 6 0
tests/misc/flist_reload.c 19 0
File ChangeLog changed (mode: 100644) (index befce3a93..924c75ffe)
8 8
9 9 Slightly improve documentation of "columncount:" in 'lsoptions'. Slightly improve documentation of "columncount:" in 'lsoptions'.
10 10
11 Avoid views scrolling unnecessarily in response to file-system changes
12 that add or remove files before the first visible line. Thanks to
13 justpretending2.
14
11 15 Fixed `:highlight Group cterm=combine,none gui=combine,none` resulting in Fixed `:highlight Group cterm=combine,none gui=combine,none` resulting in
12 16 `cterm=combine` and `gui=combine`. `cterm=combine` and `gui=combine`.
13 17
File src/filelist.c changed (mode: 100644) (index 4265eb699..d547940d7)
... ... merge_lists(view_t *view, dir_entry_t *entries, int len)
2445 2445 int i; int i;
2446 2446 int closest_dist; int closest_dist;
2447 2447 const int prev_pos = view->list_pos; const int prev_pos = view->list_pos;
2448 const int top_delta = view->list_pos - view->top_line;
2448 2449 trie_t *prev_names = trie_create(/*free_func=*/NULL); trie_t *prev_names = trie_create(/*free_func=*/NULL);
2449 2450
2450 2451 for(i = 0; i < len; ++i) for(i = 0; i < len; ++i)
 
... ... merge_lists(view_t *view, dir_entry_t *entries, int len)
2477 2478 closest_dist = correct_pos(view, i, dist, closest_dist); closest_dist = correct_pos(view, i, dist, closest_dist);
2478 2479 } }
2479 2480
2481 /* When possible, preserve relative placement of the current entry in the
2482 * view. Drawing code should handle out-of-range values (e.g., negative ones)
2483 * fine. */
2484 view->top_line = view->list_pos - top_delta;
2485
2480 2486 trie_free(prev_names); trie_free(prev_names);
2481 2487 } }
2482 2488
File tests/misc/flist_reload.c changed (mode: 100644) (index 85e48f352..d0478c80e)
... ... TEST(selection_is_preserved)
99 99 assert_int_equal(2, view->selected_files); assert_int_equal(2, view->selected_files);
100 100 } }
101 101
102 TEST(top_line_is_not_shifted_unnecessarily)
103 {
104 view->window_rows = 4;
105 view->top_line = 2;
106 view->list_pos = 3;
107 remove_dir("0");
108 remove_dir("1");
109
110 assert_string_equal("2", view->dir_entry[view->top_line].name);
111 assert_string_equal("3", view->dir_entry[view->list_pos].name);
112
113 populate_dir_list(view, /*reload=*/1);
114
115 assert_int_equal(0, view->top_line);
116 assert_int_equal(1, view->list_pos);
117 assert_string_equal("2", view->dir_entry[view->top_line].name);
118 assert_string_equal("3", view->dir_entry[view->list_pos].name);
119 }
120
102 121 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
103 122 /* vim: set cinoptions+=t0 filetype=c : */ /* vim: set cinoptions+=t0 filetype=c : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master