about summary refs log tree commit diff stats
path: root/input_win.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-07-08 03:18:39 +0100
committerJames Booth <boothj5@gmail.com>2012-07-08 03:18:39 +0100
commitd92499da7927b5ab4212d9353cfde20f0df56691 (patch)
treefe328117d4828ed5ebf18a57345362e3137ac640 /input_win.c
parent157a864ffe1b4c95cc9b93fdfb9abf132c8d4a88 (diff)
downloadprofani-tty-d92499da7927b5ab4212d9353cfde20f0df56691.tar.gz
Home and end keys
Diffstat (limited to 'input_win.c')
-rw-r--r--input_win.c57
1 files changed, 32 insertions, 25 deletions
diff --git a/input_win.c b/input_win.c
index 0d34e894..0322885e 100644
--- a/input_win.c
+++ b/input_win.c
@@ -234,40 +234,47 @@ static int _handle_edit(const int ch, char *input, int *size)
         return 1;
 
     case KEY_RIGHT:
-        if (inp_x <= *size)
+        if (inp_x < *size) {
             wmove(inp_win, inp_y, inp_x+1);
             
-        // current position off screen to right
-        if ((inp_x - pad_start) > cols-2) {
-            pad_start++;
-            prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
+            // current position off screen to right
+            if ((inp_x + 1 - pad_start) >= cols) {
+                pad_start++;
+                prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
+            }
         }
         return 1;
 
-        case KEY_UP:
-            prev = history_previous(input, size);
-            if (prev)
-                _replace_input(input, prev, size);
-            return 1;
-
-        case KEY_DOWN:
-            next = history_next(input, size);
-            if (next)
-                _replace_input(input, next, size);
-            return 1;
+    case KEY_UP:
+        prev = history_previous(input, size);
+        if (prev) {
+            _replace_input(input, prev, size);
+            pad_start = 0;
+            prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
+        }
+        return 1;
 
-        case KEY_HOME:
-            wmove(inp_win, inp_y, 0);
+    case KEY_DOWN:
+        next = history_next(input, size);
+        if (next) {
+            _replace_input(input, next, size);
             pad_start = 0;
             prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
-            return 1;
+        }
+        return 1;
 
-        case KEY_END:
-            if (*size > cols-2) {
-                pad_start = ((*size) - cols) + 2;
-                prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
-            }
-        wmove(inp_win, inp_y, (*size) + 1);
+    case KEY_HOME:
+        wmove(inp_win, inp_y, 0);
+        pad_start = 0;
+        prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
+        return 1;
+
+    case KEY_END:
+        wmove(inp_win, inp_y, *size);
+        if (*size > cols-2) {
+            pad_start = *size - cols + 1;
+            prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
+        }
         return 1;
 
     case 9: // tab