about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/inputwin.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 8bd64ffb..af5eeed9 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -258,6 +258,24 @@ inp_put_back(void)
     _inp_win_update_virtual();
 }
 
+static int
+_get_display_length(void)
+{
+    int len = 0;
+    gchar *curr = g_utf8_offset_to_pointer(line, 0);
+    while (*curr != '\0') {
+        gunichar curru = g_utf8_get_char(curr);
+        if (g_unichar_iswide(curru)) {
+            len += 2;
+        } else {
+            len ++;
+        }
+        curr = g_utf8_next_char(curr);
+    }
+
+    return len;
+}
+
 void
 inp_replace_input(const char * const new_input)
 {
@@ -302,7 +320,6 @@ _handle_edit(int key_type, const wint_t ch)
     char *next = NULL;
     int inp_x = getcurx(inp_win);
     int next_ch;
-
     int display_size = _get_display_length();
 
     // CTRL-LEFT
@@ -784,13 +801,3 @@ _printable(const wint_t ch)
     gunichar unichar = g_utf8_get_char(bytes);
     return g_unichar_isprint(unichar) && (ch != KEY_MOUSE);
 }
-
-static int
-_get_display_length(void)
-{
-    if (inp_size != 0) {
-        return g_utf8_strlen(line, inp_size);
-    } else {
-        return 0;
-    }
-}