Ticket #2957: broken autocompletion in mcedit
authorAndrew Borodin <aborodin@vmail.ru>
Wed, 13 Mar 2013 07:45:10 +0000 (13 11:45 +0400)
committerAndrew Borodin <aborodin@vmail.ru>
Thu, 21 Mar 2013 05:27:08 +0000 (21 09:27 +0400)
...if system and file charsets are different.

Initial step: refactoring: do actual completion word substitution
outside of editcmd_dialog_completion_show().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
src/editor/editcmd.c
src/editor/editcmd_dialogs.c
src/editor/editcmd_dialogs.h

index 61e141c..74e64c8 100644 (file)
@@ -3300,14 +3300,45 @@ edit_complete_word_cmd (WEdit * edit)
         /* more than one possible completion => ask the user */
         else
         {
+            char *curr_compl;
+
             /* !!! usually only a beep is expected and when <ALT-TAB> is !!! */
             /* !!! pressed again the selection dialog pops up, but that  !!! */
             /* !!! seems to require a further internal state             !!! */
             /*tty_beep (); */
 
             /* let the user select the preferred completion */
-            editcmd_dialog_completion_show (edit, max_len, word_len, (GString **) & compl,
-                                            num_compl);
+            curr_compl = editcmd_dialog_completion_show (edit, max_len,
+                                                         (GString **) & compl, num_compl);
+
+            if (curr_compl != NULL)
+            {
+#ifdef HAVE_CHARSET
+                GString *temp, *temp2;
+                char *curr_compl2 = curr_compl;
+
+                temp = g_string_new ("");
+                for (curr_compl += word_len; *curr_compl != '\0'; curr_compl++)
+                    g_string_append_c (temp, *curr_compl);
+
+                temp2 = str_convert_to_input (temp->str);
+
+                if (temp2 != NULL && temp2->len != 0)
+                {
+                    g_string_free (temp, TRUE);
+                    temp = temp2;
+                }
+                else
+                    g_string_free (temp2, TRUE);
+                for (curr_compl = temp->str; *curr_compl != '\0'; curr_compl++)
+                    edit_insert (edit, *curr_compl);
+                g_string_free (temp, TRUE);
+#else
+                for (curr_compl += word_len; *curr_compl != '\0'; curr_compl++)
+                    edit_insert (edit, *curr_compl);
+#endif
+                g_free (curr_compl2);
+            }
         }
     }
 
index 1443c07..c18bac0 100644 (file)
@@ -336,9 +336,8 @@ editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean c
 /* --------------------------------------------------------------------------------------------- */
 /* let the user select its preferred completion */
 
-void
-editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
-                                GString ** compl, int num_compl)
+char *
+editcmd_dialog_completion_show (const WEdit * edit, int max_len, GString ** compl, int num_compl)
 {
 
     int start_x, start_y, offset, i;
@@ -388,35 +387,13 @@ editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
     if (run_dlg (compl_dlg) == B_ENTER)
     {
         listbox_get_current (compl_list, &curr, NULL);
-        if (curr)
-        {
-#ifdef HAVE_CHARSET
-            GString *temp, *temp2;
-            temp = g_string_new ("");
-            for (curr += word_len; *curr; curr++)
-                g_string_append_c (temp, *curr);
-
-            temp2 = str_convert_to_input (temp->str);
-
-            if (temp2 && temp2->len)
-            {
-                g_string_free (temp, TRUE);
-                temp = temp2;
-            }
-            else
-                g_string_free (temp2, TRUE);
-            for (curr = temp->str; *curr; curr++)
-                edit_insert (edit, *curr);
-            g_string_free (temp, TRUE);
-#else
-            for (curr += word_len; *curr; curr++)
-                edit_insert (edit, *curr);
-#endif
-        }
+        curr = g_strdup (curr);
     }
 
     /* destroy dialog before return */
     destroy_dlg (compl_dlg);
+
+    return curr;
 }
 
 /* --------------------------------------------------------------------------------------------- */
index 24b9008..f691c85 100644 (file)
@@ -25,7 +25,8 @@ gboolean editcmd_dialog_search_show (WEdit * edit);
 
 int editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean cancel);
 
-void editcmd_dialog_completion_show (WEdit *, int, int, GString **, int);
+char *editcmd_dialog_completion_show (const WEdit * edit, int max_len, GString ** compl,
+                                      int num_compl);
 
 void editcmd_dialog_select_definition_show (WEdit *, char *, int, int, struct etags_hash_struct *,
                                             int);