diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-05-29 11:26:18 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2020-05-29 11:26:18 +0200 |
commit | bfaf737efad0766e62e8c9100a7c96ca97346e51 (patch) | |
tree | a39e3277a5805dbe848b92ab8d714b9d4dc2d364 /src/tools | |
parent | e19bf0e30321981ca46ff3370f479679ebc7e240 (diff) | |
download | profani-tty-bfaf737efad0766e62e8c9100a7c96ca97346e51.tar.gz |
urlopen: get last URL first
Fix https://github.com/profanity-im/profanity/issues/1348
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/autocomplete.c | 29 | ||||
-rw-r--r-- | src/tools/autocomplete.h | 3 |
2 files changed, 24 insertions, 8 deletions
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 6c960ba2..ca5fe772 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -134,6 +134,23 @@ autocomplete_update(Autocomplete ac, char **items) } void +autocomplete_add_reverse(Autocomplete ac, const char *item) +{ + if (ac) { + char *item_cpy; + GList *curr = g_list_find_custom(ac->items, item, (GCompareFunc)strcmp); + + // if item already exists + if (curr) { + return; + } + + item_cpy = strdup(item); + ac->items = g_list_prepend(ac->items, item_cpy); + } +} + +void autocomplete_add(Autocomplete ac, const char *item) { if (ac) { @@ -148,8 +165,6 @@ autocomplete_add(Autocomplete ac, const char *item) item_cpy = strdup(item); ac->items = g_list_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp); } - - return; } void @@ -385,14 +400,14 @@ autocomplete_param_no_with_func(const char *const input, char *command, int arg_ return NULL; } -/* remove the first message if we have more than max */ +/* remove the last message if we have more than max */ void -autocomplete_remove_older_than_max(Autocomplete ac, int maxsize) +autocomplete_remove_older_than_max_reverse(Autocomplete ac, int maxsize) { if (autocomplete_length(ac) > maxsize) { - GList *first = g_list_nth(ac->items, 0); - if (first) { - ac->items = g_list_delete_link(ac->items, first); + GList *last = g_list_last(ac->items); + if (last) { + ac->items = g_list_delete_link(ac->items, last); } } } diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h index 10bbbf61..6f4fe9c7 100644 --- a/src/tools/autocomplete.h +++ b/src/tools/autocomplete.h @@ -55,6 +55,7 @@ void autocomplete_add_all(Autocomplete ac, char **items); void autocomplete_update(Autocomplete ac, char **items); void autocomplete_remove(Autocomplete ac, const char *const item); void autocomplete_remove_all(Autocomplete ac, char **items); +void autocomplete_add_reverse(Autocomplete ac, const char *item); // find the next item prefixed with search string gchar* autocomplete_complete(Autocomplete ac, const gchar *search_str, gboolean quote, gboolean previous); @@ -75,5 +76,5 @@ void autocomplete_reset(Autocomplete ac); gboolean autocomplete_contains(Autocomplete ac, const char *value); -void autocomplete_remove_older_than_max(Autocomplete ac, int maxsize); +void autocomplete_remove_older_than_max_reverse(Autocomplete ac, int maxsize); #endif |