diff --git a/src/command/command.c b/src/command/command.c index 536ce854..b579fdcf 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -2169,6 +2169,14 @@ _form_autocomplete(char *input, int *size) } // handle jid-multi (remove) + if ((g_strcmp0(args[0], "remove") == 0) && field_type == FIELD_JID_MULTI) { + Autocomplete ac = form_get_value_ac(form, tag); + found = autocomplete_param_with_ac(input, size, beginning->str, ac, TRUE); + g_string_free(beginning, TRUE); + if (found != NULL) { + return found; + } + } } found = autocomplete_param_with_ac(input, size, "/form set", form->tag_ac, TRUE); diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 842ec22a..0fe8f166 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -99,16 +99,18 @@ autocomplete_length(Autocomplete ac) void autocomplete_add(Autocomplete ac, const char *item) { - char *item_cpy; - GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp); + if (ac != NULL) { + char *item_cpy; + GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp); - // if item already exists - if (curr != NULL) { - return; + // if item already exists + if (curr != NULL) { + return; + } + + item_cpy = strdup(item); + ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp); } - - item_cpy = strdup(item); - ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp); return; } diff --git a/src/xmpp/form.c b/src/xmpp/form.c index 13b652f4..25a704d9 100644 --- a/src/xmpp/form.c +++ b/src/xmpp/form.c @@ -234,7 +234,6 @@ form_create(xmpp_stanza_t * const form_stanza) char *value = xmpp_stanza_get_text(field_child); if (value != NULL) { field->values = g_slist_append(field->values, strdup(value)); - xmpp_free(ctx, value); if (field->type_t == FIELD_TEXT_MULTI) { GString *ac_val = g_string_new(""); @@ -242,6 +241,11 @@ form_create(xmpp_stanza_t * const form_stanza) autocomplete_add(field->value_ac, ac_val->str); g_string_free(ac_val, TRUE); } + if (field->type_t == FIELD_JID_MULTI) { + autocomplete_add(field->value_ac, value); + } + + xmpp_free(ctx, value); } // handle options @@ -502,6 +506,9 @@ _form_add_unique_value(DataForm *form, const char * const tag, char *value) } field->values = g_slist_append(field->values, strdup(value)); + if (field->type_t == FIELD_JID_MULTI) { + autocomplete_add(field->value_ac, value); + } form->modified = TRUE; return TRUE; } @@ -526,6 +533,9 @@ _form_remove_value(DataForm *form, const char * const tag, char *value) free(found->data); found->data = NULL; field->values = g_slist_delete_link(field->values, found); + if (field->type_t == FIELD_JID_MULTI) { + autocomplete_remove(field->value_ac, value); + } form->modified = TRUE; return TRUE; } else {