1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

urlopen: get last URL first

Fix https://github.com/profanity-im/profanity/issues/1348
This commit is contained in:
Michael Vetter 2020-05-29 11:26:18 +02:00
parent e19bf0e303
commit bfaf737efa
3 changed files with 26 additions and 10 deletions

View File

@ -133,6 +133,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)
{
@ -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);
}
}
}

View File

@ -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

View File

@ -1163,9 +1163,9 @@ wins_add_urls_ac(const ProfWin *const win, const ProfMessage *const message)
{
gchar *word = g_match_info_fetch (match_info, 0);
autocomplete_add(win->urls_ac, word);
autocomplete_add_reverse(win->urls_ac, word);
// for people who run profanity a long time, we don't want to waste a lot of memory
autocomplete_remove_older_than_max(win->urls_ac, 20);
autocomplete_remove_older_than_max_reverse(win->urls_ac, 20);
g_free (word);
g_match_info_next (match_info, NULL);