diff --git a/src/browser.c b/src/browser.c index 9bcecfa..73ff293 100644 --- a/src/browser.c +++ b/src/browser.c @@ -72,15 +72,12 @@ char *do_browser(char *path) read_directory_contents: /* We come here when we refresh or select a new directory. */ - /* Start with no key pressed. */ - kbinput = ERR; - path = mallocstrassn(path, get_full_path(newpath ? newpath : path)); if (path != NULL && newpath != NULL) dir = opendir(path); - if (path == NULL || dir == NULL) { + if ((path == NULL || dir == NULL) && kbinput != KEY_WINCH) { statusline(ALERT, "Cannot open directory: %s", strerror(errno)); /* If we don't have a file list yet, there is nothing to show. */ if (filelist == NULL) { @@ -88,6 +85,7 @@ char *do_browser(char *path) lastmessage = HUSH; free(path); free(present_name); + present_name = NULL; return NULL; } path = mallocstrcpy(path, present_path); @@ -103,6 +101,9 @@ char *do_browser(char *path) dir = NULL; } + /* Now, start with no key pressed. */ + kbinput = ERR; + /* If given, reselect the present_name and then discard it. */ if (present_name != NULL) { browser_select_dirname(present_name); @@ -131,20 +132,6 @@ char *do_browser(char *path) bottombars(MBROWSER); -#ifndef NANO_TINY - if (kbinput == KEY_WINCH) { - /* Remember the selected file, to be able to reselect it. */ - present_name = strdup(filelist[selected]); - - /* Reopen the current directory. */ - dir = opendir(path); - if (dir != NULL) - goto read_directory_contents; - - statusline(ALERT, _("Error reading %s: %s"), path, strerror(errno)); - kbinput = ERR; - } -#endif /* Display (or redisplay) the file list if we don't have a key yet, * or the list has changed, or the selected file has changed. */ if (kbinput == ERR || old_selected != selected) @@ -156,7 +143,7 @@ char *do_browser(char *path) #ifndef NANO_TINY if (kbinput == KEY_WINCH) - continue; + goto read_directory_contents; #endif #ifndef DISABLE_MOUSE @@ -194,16 +181,27 @@ char *do_browser(char *path) if (func == total_refresh) { total_redraw(); - /* Simulate a window resize to force a directory reread. */ #ifndef NANO_TINY - kbinput = KEY_WINCH; + /* Remember the selected file, to be able to reselect it. */ + if (present_name != NULL) + free(present_name); + present_name = strdup(filelist[selected]); + + /* Try opening and reading the current working directory. */ + newpath = strdup(present_path); + goto read_directory_contents; #endif } else if (func == do_help_void) { #ifndef DISABLE_HELP do_help_void(); - /* The window dimensions might have changed, so act as if. */ #ifndef NANO_TINY - kbinput = KEY_WINCH; + if (present_name != NULL) + free(present_name); + present_name = strdup(filelist[selected]); + + /* Try opening and reading the current working directory. */ + newpath = strdup(present_path); + goto read_directory_contents; #endif #else say_there_is_no_help();