about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c8
-rw-r--r--src/tools/autocomplete.c22
-rw-r--r--src/xmpp/form.c19
3 files changed, 39 insertions, 10 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 68df1cc7..536ce854 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -2159,6 +2159,14 @@ _form_autocomplete(char *input, int *size)
                 }
 
                 // handle text-multi (remove)
+                if ((g_strcmp0(args[0], "remove") == 0) && field_type == FIELD_TEXT_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;
+                    }
+                }
 
                 // handle jid-multi (remove)
             }
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c
index efff6ee0..842ec22a 100644
--- a/src/tools/autocomplete.c
+++ b/src/tools/autocomplete.c
@@ -115,19 +115,21 @@ autocomplete_add(Autocomplete ac, const char *item)
 void
 autocomplete_remove(Autocomplete ac, const char * const item)
 {
-    GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
+    if (ac != NULL) {
+        GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
 
-    if (!curr) {
-        return;
-    }
+        if (!curr) {
+            return;
+        }
 
-    // reset last found if it points to the item to be removed
-    if (ac->last_found == curr) {
-        ac->last_found = NULL;
-    }
+        // 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);
+        free(curr->data);
+        ac->items = g_slist_delete_link(ac->items, curr);
+    }
 
     return;
 }
diff --git a/src/xmpp/form.c b/src/xmpp/form.c
index 21382e06..13b652f4 100644
--- a/src/xmpp/form.c
+++ b/src/xmpp/form.c
@@ -225,6 +225,7 @@ form_create(xmpp_stanza_t * const form_stanza)
 
             // handle repeated field children
             xmpp_stanza_t *field_child = xmpp_stanza_get_children(field_stanza);
+            int value_index = 1;
             while (field_child != NULL) {
                 child_name = xmpp_stanza_get_name(field_child);
 
@@ -234,6 +235,13 @@ form_create(xmpp_stanza_t * const form_stanza)
                     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("");
+                            g_string_printf(ac_val, "val%d", value_index++);
+                            autocomplete_add(field->value_ac, ac_val->str);
+                            g_string_free(ac_val, TRUE);
+                        }
                     }
 
                 // handle options
@@ -461,6 +469,13 @@ _form_add_value(DataForm *form, const char * const tag, char *value)
             FormField *field = curr->data;
             if (g_strcmp0(field->var, var) == 0) {
                 field->values = g_slist_append(field->values, strdup(value));
+                if (field->type_t == FIELD_TEXT_MULTI) {
+                    int total = g_slist_length(field->values);
+                    GString *value_index = g_string_new("");
+                    g_string_printf(value_index, "val%d", total);
+                    autocomplete_add(field->value_ac, value_index->str);
+                    g_string_free(value_index, TRUE);
+                }
                 form->modified = TRUE;
                 return;
             }
@@ -539,6 +554,10 @@ _form_remove_text_multi_value(DataForm *form, const char * const tag, int index)
                     free(item->data);
                     item->data = NULL;
                     field->values = g_slist_delete_link(field->values, item);
+                    GString *value_index = g_string_new("");
+                    g_string_printf(value_index, "val%d", index+1);
+                    autocomplete_remove(field->value_ac, value_index->str);
+                    g_string_free(value_index, TRUE);
                     form->modified = TRUE;
                     return TRUE;
                 } else {