nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 77457fa6e95e2139686ec81566c7fd765ad0ff45
parent 9c45b5da6c191f2994a45b7e78398cbc021b381e
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sun, 10 Oct 2021 10:21:24 +0200

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.

Diffstat:
Msrc/prompt.c | 11++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/prompt.c b/src/prompt.c @@ -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); }