(edit_complete_word_cmd): make correct charset conversion
authorAndrew Borodin <aborodin@vmail.ru>
Fri, 15 Mar 2013 05:16:56 +0000 (15 09:16 +0400)
committerAndrew Borodin <aborodin@vmail.ru>
Thu, 28 Mar 2013 12:50:22 +0000 (28 16:50 +0400)
...before insert autocompletion result.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
src/editor/editcmd.c

index 74e64c8..2d69b31 100644 (file)
@@ -1496,6 +1496,32 @@ edit_redraw_page_cb (void *data, void *user_data)
 }
 
 /* --------------------------------------------------------------------------------------------- */
+/**
+ * Insert autocompleted word into editor.
+ *
+ * @param edit       editor object
+ * @param completion word for completion
+ * @param word_len   offset from begining for insert
+ */
+
+static void
+edit_complete_word_insert_recoded_completion (WEdit * edit, char *completion, gsize word_len)
+{
+#ifdef HAVE_CHARSET
+    GString *temp;
+
+    temp = str_convert_to_input (completion);
+
+    for (completion = temp->str + word_len; *completion != '\0'; completion++)
+        edit_insert (edit, *completion);
+    g_string_free (temp, TRUE);
+#else
+    for (completion += word_len; *completion != '\0'; completion++)
+        edit_insert (edit, *completion);
+#endif
+}
+
+/* --------------------------------------------------------------------------------------------- */
 /*** public functions ****************************************************************************/
 /* --------------------------------------------------------------------------------------------- */
 
@@ -3293,10 +3319,7 @@ edit_complete_word_cmd (WEdit * edit)
     {
         /* insert completed word if there is only one match */
         if (num_compl == 1)
-        {
-            for (i = word_len; i < compl[0]->len; i++)
-                edit_insert (edit, *(compl[0]->str + i));
-        }
+            edit_complete_word_insert_recoded_completion (edit, compl[0]->str, word_len);
         /* more than one possible completion => ask the user */
         else
         {
@@ -3313,31 +3336,8 @@ edit_complete_word_cmd (WEdit * edit)
 
             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);
+                edit_complete_word_insert_recoded_completion (edit, curr_compl, word_len);
+                g_free (curr_compl);
             }
         }
     }