prompt: avoid resetting the history pointer when the search is cancelled

When the user immediately cancels a search (^W^C), then nothing in
the history stack has changed, so then there is no need to reset the
history pointer to the bottom.

This slightly improves the fix for https://savannah.gnu.org/bugs/?61316.
master
Benno Schulenberg 2021-10-10 10:21:24 +02:00
parent 9c45b5da6c
commit 77457fa6e9
1 changed files with 6 additions and 5 deletions

View File

@ -454,9 +454,6 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
size_t fragment_length = 0;
/* The length of the fragment that the user tries to tab complete. */
#endif
if (history_list != NULL)
reset_history_pointer_for(*history_list);
#endif /* ENABLE_HISTORIES */
if (typing_x > strlen(answer))
@ -506,6 +503,10 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
#ifdef ENABLE_HISTORIES
if (func == get_older_item) {
if (history_list != NULL) {
/* If this is the first step into history, start at the bottom. */
if (magichistory == NULL)
reset_history_pointer_for(*history_list);
/* If we're scrolling up at the bottom of the history list
* and answer isn't blank, save answer in magichistory. */
if ((*history_list)->next == NULL)
@ -566,8 +567,8 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
}
#ifdef ENABLE_HISTORIES
/* Put the history pointer back at the bottom of the list. */
if (history_list != NULL) {
/* If the history pointer was moved, point it at the bottom again. */
if (magichistory != NULL) {
reset_history_pointer_for(*history_list);
free(magichistory);
}