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 <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2013-03-13 11:45:10 +04:00
parent 68d5b0d610
commit 7fe85d0bd8
3 changed files with 40 additions and 31 deletions

View 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);
}
}
}

View 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;
}
/* --------------------------------------------------------------------------------------------- */

View 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);