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/autocomplete.c | |
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/autocomplete.c')
-rw-r--r-- | src/tools/autocomplete.c | 29 |
1 files changed, 22 insertions, 7 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); } } } |