about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-07-15 21:30:23 +0100
committerJames Booth <boothj5@gmail.com>2014-07-15 21:30:23 +0100
commitcc62fe376cd40cf3ad38e16634a32099825579d0 (patch)
treed43bb278269ba3fc01486ad882cfbd480907db74
parent2f3234a5f50639911add9a24c32095a92791502e (diff)
downloadprofani-tty-cc62fe376cd40cf3ad38e16634a32099825579d0.tar.gz
Finished chat room nick autocomplete
-rw-r--r--src/muc.c30
-rw-r--r--src/tools/autocomplete.c2
2 files changed, 22 insertions, 10 deletions
diff --git a/src/muc.c b/src/muc.c
index f84a52c1..35868d27 100644
--- a/src/muc.c
+++ b/src/muc.c
@@ -579,16 +579,28 @@ muc_autocomplete(char *input, int *size)
         char *result = NULL;
         if (last_space == NULL) {
             result = autocomplete_complete(nick_ac, input, FALSE);
+            if (result != NULL) {
+                ui_replace_input(input, result, size);
+                g_free(result);
+                return;
+            }
         } else {
-            int len = (last_space - input);
-            char *start_str = strndup(input, len);
-            result = autocomplete_param_with_ac(input, size, start_str, nick_ac, FALSE);
-            free(start_str);
-        }
-        if (result != NULL) {
-            ui_replace_input(input, result, size);
-            g_free(result);
-            return;
+            char *search_str = last_space+1;
+            if (*search_str != '\0') {
+                result = autocomplete_complete(nick_ac, search_str, FALSE);
+                if (result != NULL) {
+                    if (g_str_has_suffix(input, result) == FALSE) {
+                        gchar *start_str = g_strndup(input, search_str - input);
+                        GString *replace_with = g_string_new(start_str);
+                        g_string_append(replace_with, result);
+                        ui_replace_input(input, replace_with->str, size);
+                        g_string_free(replace_with, TRUE);
+                        g_free(start_str);
+                        g_free(result);
+                        return;
+                    }
+                }
+            }
         }
     }
 }
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c
index 9a57ddac..424fed84 100644
--- a/src/tools/autocomplete.c
+++ b/src/tools/autocomplete.c
@@ -171,7 +171,7 @@ autocomplete_complete(Autocomplete ac, gchar *search_str, gboolean quote)
 
     // subsequent search attempt
     } else {
-        // search from here+1 tp end
+        // search from here+1 to end
         found = _search_from(ac, g_slist_next(ac->last_found), quote);
         if (found != NULL)
             return found;