From 1b47306254042cd33f2256d4596ee2fbcf66397c Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Mon, 9 May 2016 19:48:47 +0530 Subject: [PATCH] browser: remember selected file despite of update in cwd Use prev_dir mechanism to re-select already selected file when number of files in current working directory changes on refresh. Also, move the highlight when expected name is not found so that the changed selection will be noticed. This fixes http://savannah.gnu.org/bugs/?47812. Signed-off-by: Rishabh Dave --- src/browser.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/browser.c b/src/browser.c index e688e4d..4e7db17 100644 --- a/src/browser.c +++ b/src/browser.c @@ -65,7 +65,7 @@ char *do_browser(char *path, DIR *dir) UNSET(CONST_UPDATE); change_browser_directory: - /* We go here after we select a new directory. */ + /* We come here when we refresh or select a new directory. */ /* Start with no key pressed. */ kbinput = ERR; @@ -174,8 +174,18 @@ char *do_browser(char *path, DIR *dir) if (func == total_refresh) { total_redraw(); - /* Simulate a window resize. */ - kbinput = KEY_WINCH; + + /* Remember the selected file, to be able to reselect it. */ + prev_dir = strdup(filelist[selected]); + + /* Reopen the current directory. */ + dir = opendir(path); + if (dir == NULL) { + statusbar(_("Error reading %s: %s"), path, strerror(errno)); + beep(); + continue; + } + goto change_browser_directory; } else if (func == do_help_void) { #ifndef DISABLE_HELP do_help_void(); @@ -684,6 +694,11 @@ void browser_select_dirname(const char *needle) break; } } + + /* If the sought name isn't found, move the highlight so that the + * changed selection will be noticed. */ + if (looking_at == filelist_len) + --selected; } /* Set up the system variables for a filename search. Return -1 or -2 if -- 2.8.2