From 77af739bdd1b822ce2219efe779525bf3d158b8d Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 15 Mar 2013 09:16:56 +0400 Subject: [PATCH] (edit_complete_word_cmd): make correct charset conversion ...before insert autocompletion result. Signed-off-by: Andrew Borodin Signed-off-by: Slava Zanko --- src/editor/editcmd.c | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 74e64c8c1..2d69b31cb 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -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); } } } -- 2.11.4.GIT