diff --git a/src/files.c b/src/files.c index 2b585116..523e75dd 100644 --- a/src/files.c +++ b/src/files.c @@ -2756,15 +2756,14 @@ char **cwd_tab_completion(const char *buf, bool allow_files, size_t * position should be advanced. refresh_func is the function we will * call to refresh the edit window. */ char *input_tab(char *buf, bool allow_files, size_t *place, - bool *lastwastab, bool *listed) + bool *lastwastab, void (*refresh_func)(void)) { size_t num_matches = 0, buf_len; char **matches = NULL; + bool listed = FALSE; assert(buf != NULL && place != NULL && *place <= strlen(buf) && - lastwastab != NULL && listed != NULL); - - *listed = FALSE; + lastwastab != NULL && refresh_func != NULL); /* If the word starts with `~' and there is no slash in the word, * then try completing this word as a username. */ @@ -2897,7 +2896,7 @@ char *input_tab(char *buf, bool allow_files, size_t *place, } wnoutrefresh(edit); - *listed = TRUE; + listed = TRUE; } free(mzero); @@ -2905,6 +2904,10 @@ char *input_tab(char *buf, bool allow_files, size_t *place, free_chararray(matches, num_matches); + /* Refresh the edit window just in case a previous tab showed a list. */ + if (!listed) + refresh_func(); + return buf; } #endif /* !DISABLE_TABCOMP */ diff --git a/src/prompt.c b/src/prompt.c index e621bc63..53e1ad64 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -529,7 +529,7 @@ void update_bar_if_needed(void) /* Get a string of input at the statusbar prompt. */ functionptrtype get_prompt_string(int *actual, bool allow_tabs, #ifndef DISABLE_TABCOMP - bool allow_files, bool *listed, + bool allow_files, #endif const char *curranswer, #ifndef DISABLE_HISTORIES @@ -619,7 +619,7 @@ functionptrtype get_prompt_string(int *actual, bool allow_tabs, #endif if (allow_tabs) answer = input_tab(answer, allow_files, &statusbar_x, - &tabbed, listed); + &tabbed, refresh_func); update_the_statusbar(); } else @@ -735,9 +735,7 @@ int do_prompt(bool allow_tabs, va_list ap; int retval; functionptrtype func; -#ifndef DISABLE_TABCOMP - bool listed = FALSE; -#endif + /* Save a possible current statusbar x position. */ size_t was_statusbar_x = statusbar_x; size_t was_pww = statusbar_pww; @@ -753,7 +751,7 @@ int do_prompt(bool allow_tabs, func = get_prompt_string(&retval, allow_tabs, #ifndef DISABLE_TABCOMP - allow_files, &listed, + allow_files, #endif curranswer, #ifndef DISABLE_HISTORIES @@ -785,13 +783,6 @@ int do_prompt(bool allow_tabs, fprintf(stderr, "answer = \"%s\"\n", answer); #endif -#ifndef DISABLE_TABCOMP - /* If we've done tab completion, and a list of filename matches - * was printed in the edit window, clear them off. */ - if (listed) - refresh_func(); -#endif - return retval; } diff --git a/src/proto.h b/src/proto.h index 7985c76d..5373476b 100644 --- a/src/proto.h +++ b/src/proto.h @@ -340,7 +340,7 @@ char **username_tab_completion(const char *buf, size_t *num_matches, char **cwd_tab_completion(const char *buf, bool allow_files, size_t *num_matches, size_t buf_len); char *input_tab(char *buf, bool allow_files, size_t *place, - bool *lastwastab, bool *listed); + bool *lastwastab, void (*refresh_func)(void)); #endif const char *tail(const char *path); #ifndef DISABLE_HISTORIES @@ -532,7 +532,7 @@ void update_the_statusbar(void); void update_bar_if_needed(void); functionptrtype get_prompt_string(int *value, bool allow_tabs, #ifndef DISABLE_TABCOMP - bool allow_files, bool *listed, + bool allow_files, #endif const char *curranswer, #ifndef DISABLE_HISTORIES