about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-06-01 00:15:01 +0100
committerJames Booth <boothj5@gmail.com>2016-06-01 00:15:01 +0100
commit78785fa7e62eb6f8c30a015a180b4b33805d7317 (patch)
treedf01ba5611b3ea7687d46346e2f91fd1c0b1b69c
parent28cc04ca7d994e408cac3ca29a8d6ce6d4f1e8e2 (diff)
downloadprofani-tty-78785fa7e62eb6f8c30a015a180b4b33805d7317.tar.gz
Complete no arg for /join properties
-rw-r--r--src/command/cmd_ac.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 6b85b6a1..63ad4fbc 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -2566,32 +2566,39 @@ _join_autocomplete(ProfWin *window, const char *const input)
     char *found = NULL;
     gboolean result = FALSE;
 
-    found = autocomplete_param_with_func(input, "/join", bookmark_find);
-    if (found) {
-        return found;
-    }
-
-    gchar **args = parse_args(input, 2, 4, &result);
+    gchar **args = parse_args(input, 1, 5, &result);
 
-    if ((strncmp(input, "/join", 5) == 0) && (result == TRUE)) {
-        GString *beginning = g_string_new("/join ");
-        g_string_append(beginning, args[0]);
-        if (args[1] && args[2]) {
-            g_string_append(beginning, " ");
-            g_string_append(beginning, args[1]);
-            g_string_append(beginning, " ");
-            g_string_append(beginning, args[2]);
+    if (result) {
+        gboolean space_at_end = g_str_has_suffix(input, " ");
+        GString *beginning = g_string_new("/join");
+        int num_args = g_strv_length(args);
+        if ((num_args == 1 && space_at_end) || (num_args == 2 && !space_at_end)) {
+            g_string_append_printf(beginning, " %s", args[0]);
+            found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE);
+            g_string_free(beginning, TRUE);
+            if (found) {
+                g_strfreev(args);
+                return found;
+            }
         }
-        found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE);
-        g_string_free(beginning, TRUE);
-        if (found) {
-            g_strfreev(args);
-            return found;
+        if ((num_args == 3 && space_at_end) || (num_args == 4 && !space_at_end)) {
+            g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
+            found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE);
+            g_string_free(beginning, TRUE);
+            if (found) {
+                g_strfreev(args);
+                return found;
+            }
         }
     }
 
     g_strfreev(args);
 
+    found = autocomplete_param_with_func(input, "/join", bookmark_find);
+    if (found) {
+        return found;
+    }
+
     return NULL;
 }