about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-01-03 01:42:02 +0000
committerJames Booth <boothj5@gmail.com>2013-01-03 01:42:02 +0000
commit05292a0eb8bd12c84b22271e55c0bc661a87362d (patch)
tree00bceff7559c66da28f1bcf81b8f3a4cb499ff68
parent73cdcb87efd3bc9bfc7bb88db5e434a8b5f63cf9 (diff)
downloadprofani-tty-05292a0eb8bd12c84b22271e55c0bc661a87362d.tar.gz
Handle backspace at end of input for wide chars
-rw-r--r--src/input_win.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/input_win.c b/src/input_win.c
index ae8b400c..bcfcc78b 100644
--- a/src/input_win.c
+++ b/src/input_win.c
@@ -269,6 +269,11 @@ _handle_edit(const wint_t ch, char *input, int *size)
     int inp_y = 0;
     int inp_x = 0;
     int next_ch;
+    int display_size = 0;
+
+    if (*size != 0) {
+        display_size = g_utf8_strlen(input, *size);
+    }
 
     getmaxyx(stdscr, rows, cols);
     getyx(inp_win, inp_y, inp_x);
@@ -324,13 +329,18 @@ _handle_edit(const wint_t ch, char *input, int *size)
     case 127:
     case KEY_BACKSPACE:
         contact_list_reset_search_attempts();
-        if (*size > 0) {
+        if (display_size > 0) {
 
             // if at end, delete last char
-            if (inp_x >= *size) {
+            if (inp_x >= display_size) {
                 wmove(inp_win, inp_y, inp_x-1);
                 wdelch(inp_win);
                 (*size)--;
+                if (*size > 0) {
+                    if (!g_unichar_validate(input[*size])) {
+                        (*size)--;
+                    }
+                }
 
             // if in middle, delete and shift chars left
             } else if (inp_x > 0 && inp_x < *size) {