Add a buffer holder for current search/replace data, so we don't lose it when going back through history

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1341 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2003-01-09 05:29:58 +00:00
parent 6cd143db7a
commit 8031f83422
1 changed files with 17 additions and 1 deletions

18
winio.c
View File

@ -208,8 +208,9 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* for history */ /* for history */
char *history = NULL; char *history = NULL;
char *currentbuf = NULL;
char *complete = NULL; char *complete = NULL;
int last_kbinput = 0; int last_kbinput = 0, ret2cb = 0;
#endif #endif
xend = strlen(def); xend = strlen(def);
x = xend; x = xend;
@ -350,6 +351,14 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
case KEY_UP: case KEY_UP:
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (history_list) { if (history_list) {
/* If there's no previous temp holder, or if we already arrowed
back down to it and (possibly edited ir), update the holder */
if (currentbuf == NULL || (ret2cb == 1 && strcmp(currentbuf, answer))) {
currentbuf = mallocstrcpy(currentbuf, answer);
ret2cb = 0;
}
/* get older search from the history list */ /* get older search from the history list */
if ((history = get_history_older(history_list))) { if ((history = get_history_older(history_list))) {
answer = mallocstrcpy(answer, history); answer = mallocstrcpy(answer, history);
@ -369,6 +378,13 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
if ((history = get_history_newer(history_list))) { if ((history = get_history_newer(history_list))) {
answer = mallocstrcpy(answer, history); answer = mallocstrcpy(answer, history);
xend = strlen(history); xend = strlen(history);
/* Else if we ran out of history, regurgitate the temporary
buffer */
} else if (currentbuf != NULL) {
answer = mallocstrcpy(answer, currentbuf);
xend = strlen(currentbuf);
ret2cb = 1;
} else { } else {
answer = mallocstrcpy(answer, ""); answer = mallocstrcpy(answer, "");
xend = 0; xend = 0;