about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2021-10-21 17:01:54 +0300
committerMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2021-10-21 17:21:00 +0300
commit6b0f15a1c90116a01463a8c9e26c32f4112810e7 (patch)
tree9dd89fd90ea63d40c271d5a870fce18669872fe3
parentcd16264d2bfb8ffb7afd9bd42a39e06c019f5915 (diff)
downloadprofani-tty-6b0f15a1c90116a01463a8c9e26c32f4112810e7.tar.gz
Remove autocomplete for /correct-editor
We decided that it was better to remove autocomplete for this command,
since adding it only introduced problems and the command can still
function perfectly without autocomplete.
-rw-r--r--src/command/cmd_ac.c34
-rw-r--r--src/command/cmd_ac.h1
-rw-r--r--src/command/cmd_defs.c8
-rw-r--r--src/command/cmd_funcs.c6
4 files changed, 18 insertions, 31 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 88b2b2f7..a0d57a18 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -1795,7 +1795,6 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
     g_hash_table_insert(ac_funcs, "/avatar", _avatar_autocomplete);
     g_hash_table_insert(ac_funcs, "/correction", _correction_autocomplete);
     g_hash_table_insert(ac_funcs, "/correct", _correct_autocomplete);
-    g_hash_table_insert(ac_funcs, "/correct-editor", _correct_autocomplete);
     g_hash_table_insert(ac_funcs, "/software", _software_autocomplete);
     g_hash_table_insert(ac_funcs, "/url", _url_autocomplete);
     g_hash_table_insert(ac_funcs, "/executable", _executable_autocomplete);
@@ -4032,6 +4031,17 @@ _correction_autocomplete(ProfWin* window, const char* const input, gboolean prev
 static char*
 _correct_autocomplete(ProfWin* window, const char* const input, gboolean previous)
 {
+    GString* result_str = g_string_new("/correct ");
+    g_string_append(result_str, _get_last_message(window));
+    char* result = result_str->str;
+    g_string_free(result_str, FALSE);
+
+    return result;
+}
+
+char*
+_get_last_message(ProfWin* window)
+{
     char* last_message = NULL;
     switch (window->type) {
     case WIN_CHAT:
@@ -4055,27 +4065,7 @@ _correct_autocomplete(ProfWin* window, const char* const input, gboolean previou
         return NULL;
     }
 
-    // Get command
-    int len = strlen(input);
-    char command[len + 2];
-    int i = 0;
-    while (i < len) {
-        if (input[i] == ' ') {
-            break;
-        } else {
-            command[i] = input[i];
-        }
-        i++;
-    }
-    command[i] = ' ';
-    command[i + 1] = '\0';
-
-    GString* result_str = g_string_new(command);
-    g_string_append(result_str, last_message);
-    char* result = result_str->str;
-    g_string_free(result_str, FALSE);
-
-    return result;
+    return last_message;
 }
 
 static char*
diff --git a/src/command/cmd_ac.h b/src/command/cmd_ac.h
index ef715310..c0485916 100644
--- a/src/command/cmd_ac.h
+++ b/src/command/cmd_ac.h
@@ -59,5 +59,6 @@ void cmd_ac_add_form_fields(DataForm* form);
 void cmd_ac_remove_form_fields(DataForm* form);
 
 char* cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean previous);
+char* _get_last_message(ProfWin* window);
 
 #endif
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 47ab34ad..85631a34 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2623,21 +2623,19 @@ static struct cmd_t command_defs[] = {
     },
 
     { "/correct-editor",
-      parse_args_as_one, 1, 1, NULL,
+      parse_args, 0, 0, NULL,
       CMD_NOSUBFUNCS
       CMD_MAINFUNC(cmd_correct_editor)
       CMD_TAGS(
               CMD_TAG_CHAT,
               CMD_TAG_GROUPCHAT)
       CMD_SYN(
-              "/correct-editor <message>")
+              "/correct-editor")
       CMD_DESC(
               "Spawn external editor to correct and resend the last message (XEP-0308). "
-              "Use tab completion to get the last sent message. "
               "For more information on how to configure corrections, see: /help correction. "
               "Use /executable to set your favourite editor.")
-      CMD_ARGS(
-              { "message", "The corrected message." })
+      CMD_NOARGS
       CMD_NOEXAMPLES
     },
 
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index c0537087..55a05be2 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -9461,7 +9461,7 @@ cmd_change_password(ProfWin* window, const char* const command, gchar** args)
     return TRUE;
 }
 
-// Returns true if any error occured
+// Returns true if an error occured
 gboolean
 _get_message_from_editor(gchar* message, gchar** returned_message)
 {
@@ -9569,15 +9569,13 @@ cmd_correct_editor(ProfWin* window, const char* const command, gchar** args)
         return TRUE;
     }
 
-    gchar* initial_message = g_strjoinv(" ", args);
+    gchar* initial_message = _get_last_message(window);
 
     gchar* message = NULL;
     if (_get_message_from_editor(initial_message, &message)) {
         return TRUE;
     }
 
-    free(initial_message);
-
     if (window->type == WIN_CHAT) {
         ProfChatWin* chatwin = (ProfChatWin*)window;