From 7fe85d0bd8e5684d918372726b892a25d3486489 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 13 Mar 2013 11:45:10 +0400 Subject: [PATCH] Ticket #2957: broken autocompletion in mcedit ...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 --- src/editor/editcmd.c | 35 +++++++++++++++++++++++++++++++++-- src/editor/editcmd_dialogs.c | 33 +++++---------------------------- src/editor/editcmd_dialogs.h | 3 ++- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 61e141cc1..74e64c8c1 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -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 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); + } } } diff --git a/src/editor/editcmd_dialogs.c b/src/editor/editcmd_dialogs.c index 1443c07e1..c18bac065 100644 --- a/src/editor/editcmd_dialogs.c +++ b/src/editor/editcmd_dialogs.c @@ -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; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editcmd_dialogs.h b/src/editor/editcmd_dialogs.h index 24b9008fd..f691c857e 100644 --- a/src/editor/editcmd_dialogs.h +++ b/src/editor/editcmd_dialogs.h @@ -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); -- 2.11.4.GIT