From a77c368926375ee52e3105beb560b310fc1aef64 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Thu, 6 Jun 2013 00:35:53 +0200 Subject: [PATCH] Fixed wrong order of history items. The order of the history items available by '/' or ':' was wrong, the first items should be the latest added command and not the oldest one. This patch fixes also wrong ordering of history entries in the files in case when the number of items in the files is higher than the configured maximum history items. --- src/history.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/history.c b/src/history.c index 2650f76..13f6521 100644 --- a/src/history.c +++ b/src/history.c @@ -123,16 +123,16 @@ char *history_get(const char *input, gboolean prev) if (!history.active) { history.active = get_list(input); - history.active = g_list_append(history.active, g_strdup("")); /* start with latest added items */ - history.active = g_list_last(history.active); + history.active = g_list_first(history.active); + history.active = g_list_prepend(history.active, g_strdup("")); } if (prev) { - if ((new = g_list_previous(history.active))) { + if ((new = g_list_next(history.active))) { history.active = new; } - } else if ((new = g_list_next(history.active))) { + } else if ((new = g_list_previous(history.active))) { history.active = new; } @@ -203,8 +203,7 @@ static const char *get_file_by_type(HistoryType type) } /** - * Loads history items form file but eleminate duplicates. - * Oldest entries first. + * Loads history items form file but eleminate duplicates in FIFO order. */ static GList *load(const char *file) { @@ -239,10 +238,11 @@ static GList *load(const char *file) file_lock_set(fileno(f), F_UNLCK); fclose(f); + /* reverse to not use the slow g_list_last */ + list = g_list_reverse(list); + /* if list is too long - remove items from end (oldest entries) */ if (vb.config.history_max < g_list_length(list)) { - /* reverse to not use the slow g_list_last */ - list = g_list_reverse(list); while (vb.config.history_max < g_list_length(list)) { GList *last = g_list_first(list); g_free(last->data); @@ -250,8 +250,6 @@ static GList *load(const char *file) } } - list = g_list_reverse(list); - return list; } -- 2.20.1