From 772f5857f0da7e774fc8f45f51d9c8ea93a3cda0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 3 Jan 2013 23:47:45 +0000 Subject: Handle deleting wide chars in middle of input --- src/input_win.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/input_win.c b/src/input_win.c index 2404e513..a25b33e3 100644 --- a/src/input_win.c +++ b/src/input_win.c @@ -348,13 +348,22 @@ _handle_edit(const wint_t ch, char *input, int *size) // if in middle, delete and shift chars left } else if (inp_x > 0 && inp_x < display_size) { - for (i = inp_x; i < *size; i++) - input[i-1] = input[i]; - (*size)--; + gchar *start = g_utf8_substring(input, 0, inp_x - 1); + gchar *end = g_utf8_substring(input, inp_x, *size); + GString *new = g_string_new(start); + g_string_append(new, end); + + for (*size = 0; *size < strlen(new->str); (*size)++) { + input[*size] = new->str[*size]; + } + input[*size] = '\0'; + + g_free(start); + g_free(end); + g_string_free(new, FALSE); inp_clear(); - for (i = 0; i < *size; i++) - waddch(inp_win, input[i]); + wprintw(inp_win, input); wmove(inp_win, 0, inp_x -1); } -- cgit 1.4.1-2-gfad0