diff --git a/src/command/command.c b/src/command/command.c index 72b95f9a..bd5b903e 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -3547,6 +3547,15 @@ _group_autocomplete(char *input, int *size) if (result != NULL) { return result; } + + result = autocomplete_param_no_with_func(input, size, "/group add", 4, roster_find_contact); + if (result != NULL) { + return result; + } + result = autocomplete_param_no_with_func(input, size, "/group remove", 4, roster_find_contact); + if (result != NULL) { + return result; + } result = autocomplete_param_with_func(input, size, "/group add", roster_find_group); if (result != NULL) { return result; diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index d9477e99..e3829f7f 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -260,6 +260,62 @@ autocomplete_param_with_ac(char *input, int *size, char *command, return auto_msg; } +char * +autocomplete_param_no_with_func(char *input, int *size, char *command, + int arg_number, autocomplete_func func) +{ + char *result = NULL; + if (strncmp(input, command, strlen(command)) == 0 && (*size > strlen(command))) { + int i = 0; + int quote_count = 0; + char *found = NULL; + GString *result_str = NULL; + + // copy and null terminate input, count quotes + gchar inp_cpy[*size]; + for (i = 0; i < *size; i++) { + if (input[i] == '"') { + quote_count++; + } + inp_cpy[i] = input[i]; + } + inp_cpy[i] = '\0'; + g_strstrip(inp_cpy); + + // count tokens + gchar **tokens = g_strsplit(inp_cpy, " ", 0); + int num_tokens = g_strv_length(tokens); + + // if num tokens, or 2 quotes then candidate for autocompletion of last param + if (((num_tokens > arg_number - 1) && quote_count == 0) || quote_count == 2) { + + gchar *comp_str = NULL; + + // find start of autocompletion string + if (num_tokens > 3 && quote_count == 0) { + comp_str = g_strrstr(inp_cpy, tokens[arg_number - 1]); + } else { + comp_str = g_strrstr(inp_cpy, "\""); + comp_str = comp_str + 2; + } + + // autocomplete param + if (comp_str != NULL) { + found = func(comp_str); + if (found != NULL) { + result_str = g_string_new(""); + g_string_append(result_str, g_strndup(inp_cpy, strlen(inp_cpy) - strlen(comp_str))); + g_string_append(result_str, found); + result = result_str->str; + g_string_free(result_str, FALSE); + return result; + } + } + } + } + + return NULL; +} static gchar * _search_from(Autocomplete ac, GSList *curr) diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h index 3f619298..a28601d0 100644 --- a/src/tools/autocomplete.h +++ b/src/tools/autocomplete.h @@ -47,5 +47,7 @@ char * autocomplete_param_with_func(char *input, int *size, char *command, autocomplete_func func); char * autocomplete_param_with_ac(char *input, int *size, char *command, Autocomplete ac); +char * autocomplete_param_no_with_func(char *input, int *size, char *command, + int arg_number, autocomplete_func func); #endif