about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-01-17 02:21:00 +0000
committerJames Booth <boothj5@gmail.com>2013-01-17 02:21:00 +0000
commit58e62f3e63ba514371757c81bef6d7b09d37295b (patch)
tree6c77d7ed8d1c96db75b06261681d6672d43721f0
parent78d11d362dd5d66e3e3b0c14e07c7ff8547cba68 (diff)
downloadprofani-tty-58e62f3e63ba514371757c81bef6d7b09d37295b.tar.gz
ctrl-right handling
-rw-r--r--src/input_win.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/input_win.c b/src/input_win.c
index 6d1772ca..e563d451 100644
--- a/src/input_win.c
+++ b/src/input_win.c
@@ -314,13 +314,42 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
 
     // CTRL-RIGHT
     } else if ((result == KEY_CODE_YES) && (ch == 555) && (inp_x < display_size)) {
-        wmove(inp_win, 0, inp_x+1);
+        input[*size] = '\0';
+        gchar *curr_ch = g_utf8_offset_to_pointer(input, inp_x);
+        gchar *next_ch = g_utf8_find_next_char(curr_ch, NULL);
+        gunichar curr_uni;
+        gunichar next_uni;
+        gboolean moved = FALSE;
+
+        while (g_utf8_pointer_to_offset(input, next_ch) < display_size) {
+            curr_uni = g_utf8_get_char(curr_ch);
+            next_uni = g_utf8_get_char(next_ch);
+            curr_ch = next_ch;
+            next_ch = g_utf8_find_next_char(next_ch, NULL);
+
+            if (!g_unichar_isspace(curr_uni) && g_unichar_isspace(next_uni) && moved) {
+                break;
+            } else {
+                moved = TRUE;
+            }
+        }
+
+        // handle some shit
+        if (next_ch == NULL) {
+            inp_x = display_size;
+            wmove(inp_win, 0, inp_x);
+        } else {
+            glong offset = g_utf8_pointer_to_offset(input, curr_ch);
+            inp_x = offset + 1;
+            wmove(inp_win, 0, inp_x);
+        }
 
-        // current position off screen to right
-        if ((inp_x + 1 - pad_start) >= cols) {
-            pad_start++;
+        // if gone off screen to right, jump right (half a screen worth)
+        if (inp_x > pad_start + cols) {
+            pad_start = pad_start + (cols / 2);
             _inp_win_refresh();
         }
+
         return 1;
 
     // other editing keys