]> khamidou — GitHub mirrors - te.git/commitdiff
still modifying the cursor movement code
authorkhamidou <karim@lambda-expr.org>
Sun, 17 May 2009 20:25:43 +0000 (22:25 +0200)
committerkhamidou <karim@lambda-expr.org>
Sun, 17 May 2009 20:25:43 +0000 (22:25 +0200)
buffer.c
keyb.c
screen.c

index 3e8241f3c39582177b953aad5d5c037a1b064813..76b9fcdeee31d0353fb4b8025bf2318b9835bf25 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -26,14 +26,6 @@ struct te_buffer *alloc_and_insert_buffer(void)
        return b;
 }
 
-struct te_char *nth_char(struct te_char *c, int n)
-{
-}
-
-void free_char(struct te_buffer *b, struct te_char *c)
-{
-}
-
 void free_buffer(struct te_buffer *b)
 {
        if (b == NULL)
@@ -44,7 +36,6 @@ void free_buffer(struct te_buffer *b)
        free(b);
 }
 
-
 struct te_buffer* load_buffer(char *filename)
 {
        FILE *fp = fopen(filename, "r");
@@ -67,7 +58,6 @@ struct te_buffer* load_buffer(char *filename)
 }
 
 /* Compute the length of a string between two '\n' */
-
 int line_length(bstring b, int point)
 {
        if (b == NULL)
@@ -98,7 +88,7 @@ int screen_line_length(bstring b, int point)
 
        for (i = 0; i < len; i++) {
                if (bchar(b, point - i) == '\t')
-                       count += 8;
+                       count += TAB_LEN;
                else
                        count += 1;
        }
diff --git a/keyb.c b/keyb.c
index 7ec0df3aa15df0cfadcf84709efd7f8144688d8e..13a741f93a9119f618334c7e26da4a0fcd4a8076 100644 (file)
--- a/keyb.c
+++ b/keyb.c
@@ -10,10 +10,12 @@ void input_loop(void)
                        exit(0);
 
                case 'k':
+               case KEY_LEFT:
                        move_left(current_buf);
                        break;
 
                case 'l':
+               case KEY_RIGHT:
                        move_right(current_buf);
                        break;
                }
index aac2adf5b0d5e6ec430cf4a4e0b5c52146b16bf8..3606918ac1ad1a64f663478f501f1e84c1ef9cf3 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -55,24 +55,55 @@ void scroll_down(struct te_buffer *buf)
 
 }
 
+void screen_prev_line(struct te_buffer *buf)
+{
+       if (buf == NULL)
+               return;
+
+       buf->x = 0;
+       if (buf->y > 0)
+               buf->y--;
+}
+
+void screen_next_line(struct te_buffer *buf)
+{
+       if (buf == NULL)
+               return;
+
+       buf->x = 0;
+       if (buf->y < LINES)
+               buf->y++;
+}
+
 void move_left(struct te_buffer *buf)
 {
        if (buf == NULL)
                return;
 
+       if (bchar(buf->contents, buf->point) == '\n') {
+               screen_prev_line(buf);
+               prev_char(buf);
+               return;
+       }
+
+       if(prev_char(buf) == ERR)
+               return;
+
        if (buf->x > 0)
                if (bchar(buf->contents, buf->point) == '\t')
                        buf->x -= TAB_LEN;
-               else
+               else {
                        buf->x--;
+               }
 
        else if (buf->y > 0) {
                buf->y--;
                buf->x = screen_line_length(buf->contents, buf->point);
        }
 
-       prev_char(buf);
        move(buf->y, buf->x);
+       refresh();
+       miniprintf("%c, y: %d, x%d", bchar(buf->contents, buf->point), buf->y, buf->x);
 }
 
 void move_right(struct te_buffer *buf)
@@ -80,6 +111,12 @@ void move_right(struct te_buffer *buf)
        if (buf == NULL)
                return;
 
+       if (bchar(buf->contents, buf->point) == '\n') {
+               screen_next_line(buf);
+               next_char(buf);
+               return;
+       }
+
        if (next_char(buf) == ERR) /* last char of the document */
                return;
 
@@ -87,8 +124,9 @@ void move_right(struct te_buffer *buf)
                /* tab is the only character larger than 1 */
                if (bchar(buf->contents, buf->point) == '\t')
                        buf->x += TAB_LEN;
-               else
+               else {
                        buf->x++;
+               }
        }
        else if (buf->y < LINES - 3) {
                buf->y++;