degesch: little libedit details

This commit is contained in:
Přemysl Eric Janouch 2015-05-07 07:23:11 +02:00
parent 1d7903ae03
commit 85baf5ecec

View File

@ -5589,10 +5589,10 @@ on_editline_complete (EditLine *editline, int key)
unsigned char result = CC_REFRESH_BEEP;
// First prepare what Readline would have normally done for us...
const LineInfo *info = el_line (editline);
int len = info->lastchar - info->buffer;
int point = info->cursor - info->buffer;
char *copy = xstrndup (info->buffer, len);
const LineInfo *info_mb = el_line (editline);
int len = info_mb->lastchar - info_mb->buffer;
int point = info_mb->cursor - info_mb->buffer;
char *copy = xstrndup (info_mb->buffer, len);
// XXX: possibly incorrect wrt. shift state encodings
int el_start = point, el_end = point;
@ -5652,17 +5652,15 @@ on_editline_return (EditLine *editline, int key)
history_w (self->current->history, &ev, H_ENTER, line);
print_debug ("history: %d %ls", ev.num, ev.str);
}
// Convert it to multibyte to reflect the Readline interface
size_t needed = wcstombs (NULL, line, 0) + 1;
char converted[needed];
if (!needed || wcstombs (converted, line, needed) == (size_t) -1)
print_error ("encoding conversion failed");
else
process_input (g_ctx, converted);
free (line);
// process_input() expects a multibyte string
const LineInfo *info_mb = el_line (editline);
char copy[info_mb->lastchar - info_mb->buffer + 1];
memcpy (copy, info_mb->buffer, sizeof copy - 1);
copy[sizeof copy - 1] = '\0';
process_input (g_ctx, copy);
el_cursor (editline, len - point);
el_wdeletestr (editline, len);
return CC_REFRESH;