From 036c5f9c1f8321ae327dd43863f8b5cd0a29e91f Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 20 Mar 2016 13:38:09 +0000 Subject: [PATCH] Cycling through the tab-completion items from newest to oldest. This fixes Savannah bug #47205. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5752 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 2 ++ src/search.c | 19 +++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8e2f06d..1a3913aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ a semicolon instead of a comma between phrases. * src/text.c (do_cutword): Don't put cut words into the cutbuffer -- that is: treat the deletion of words like pressing Backspace/Delete. + * src/search.c (get_history_completion, find_history): Cycle through + the items from newest to oldest. This fixes Savannah bug #47205. 2016-03-19 Benno Schulenberg * src/search.c (search_init): Always remember the last typed string, diff --git a/src/search.c b/src/search.c index 635266da..9700ebe4 100644 --- a/src/search.c +++ b/src/search.c @@ -1207,7 +1207,7 @@ filestruct *find_history(const filestruct *h_start, const filestruct { const filestruct *p; - for (p = h_start; p != h_end->next && p != NULL; p = p->next) { + for (p = h_start; p != h_end->prev && p != NULL; p = p->prev) { if (strncmp(s, p->data, len) == 0) return (filestruct *)p; } @@ -1234,7 +1234,7 @@ void update_history(filestruct **h, const char *s) assert(hage != NULL && hbot != NULL); /* If this string is already in the history, delete it. */ - p = find_history(*hage, *hbot, s, strlen(s)); + p = find_history(*hbot, *hage, s, strlen(s)); if (p != NULL) { filestruct *foo, *bar; @@ -1337,25 +1337,24 @@ char *get_history_completion(filestruct **h, char *s, size_t len) assert(hage != NULL && hbot != NULL); - /* Search the history list from the current position to the - * bottom for a match of len characters. Skip over an exact - * match. */ - p = find_history((*h)->next, hbot, s, len); + /* Search the history list from the current position to the top + * for a match of len characters. Skip over an exact match. */ + p = find_history((*h)->prev, hage, s, len); while (p != NULL && strcmp(p->data, s) == 0) - p = find_history(p->next, hbot, s, len); + p = find_history(p->prev, hage, s, len); if (p != NULL) { *h = p; return mallocstrcpy(s, (*h)->data); } - /* Search the history list from the top to the current position + /* Search the history list from the bottom to the current position * for a match of len characters. Skip over an exact match. */ - p = find_history(hage, *h, s, len); + p = find_history(hbot, *h, s, len); while (p != NULL && strcmp(p->data, s) == 0) - p = find_history(p->next, *h, s, len); + p = find_history(p->prev, *h, s, len); if (p != NULL) { *h = p; -- 2.39.5