about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-01-03 23:47:45 +0000
committerJames Booth <boothj5@gmail.com>2013-01-03 23:47:45 +0000
commit772f5857f0da7e774fc8f45f51d9c8ea93a3cda0 (patch)
treefe5cd7d989cdff1370e245df540a060cdc5e46d6
parenta96e36a55d26953eb3ad6d4c4afc25309851efb0 (diff)
downloadprofani-tty-772f5857f0da7e774fc8f45f51d9c8ea93a3cda0.tar.gz
Handle deleting wide chars in middle of input
-rw-r--r--src/input_win.c19
1 files 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);
             }