mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
refactred autocomplete_remove
This commit is contained in:
parent
92763d2e68
commit
982f1174a8
@ -101,30 +101,21 @@ autocomplete_add(Autocomplete ac, const char *item)
|
||||
gboolean
|
||||
autocomplete_remove(Autocomplete ac, const char * const item)
|
||||
{
|
||||
// reset last found if it points to the item to be removed
|
||||
if (ac->last_found != NULL)
|
||||
if (g_strcmp0(ac->last_found->data, item) == 0)
|
||||
ac->last_found = NULL;
|
||||
|
||||
if (!ac->items) {
|
||||
return FALSE;
|
||||
} else {
|
||||
GSList *curr = ac->items;
|
||||
|
||||
while(curr) {
|
||||
if (g_strcmp0(curr->data, item) == 0) {
|
||||
void *current_item = curr->data;
|
||||
ac->items = g_slist_remove(ac->items, curr->data);
|
||||
free(current_item);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
|
||||
|
||||
if (!curr) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// reset last found if it points to the item to be removed
|
||||
if (ac->last_found == curr) {
|
||||
ac->last_found = NULL;
|
||||
}
|
||||
|
||||
free(curr->data);
|
||||
ac->items = g_slist_delete_link(ac->items, curr);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GSList *
|
||||
|
Loading…
Reference in New Issue
Block a user