]> khamidou — GitHub mirrors - te.git/commitdiff
finished implementing cursor motion
authorkhamidou <karim@lambda-expr.org>
Sat, 27 Jun 2009 13:37:06 +0000 (15:37 +0200)
committerkhamidou <karim@lambda-expr.org>
Sat, 27 Jun 2009 13:37:06 +0000 (15:37 +0200)
buffer.c
screen.c

index 00d18ac0d715a245caf27da857c38c8a95bfc93d..d054683e233fcd144d915cbf7c135093f9c96099 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -87,17 +87,19 @@ int screen_line_length(bstring b, int point)
        if (b == NULL)
                return -1;
 
-       int len = line_length(b, point);
        int i = 0;
        int count = 0;
 
-       for (i = 0; i < len; i++) {
-               if (bchar(b, point - i) == '\t')
+       int s_offset = bstrrchrp(b, '\n', point - 1);
+
+       for (i = s_offset + 1; bchar(b, i) != '\n'; i++) {
+               if (bchar(b, i) == '\t')
                        count += TAB_LEN;
                else
                        count += 1;
        }
 
+       return count;
 }
 
 bstring current_line_as_bstring(bstring b, int point)
index 88da079d0f8acb30022d7f9601cea4a434181d57..e1f84e5cc2f5e355ace0ba6011b46497de9bcc58 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -124,6 +124,7 @@ void screen_move_left(struct te_buffer *buf)
        
        if (curr_char(buf) == '\n') {
                        screen_prev_line(buf);
+                       buf->x = screen_line_length(buf->contents, buf->point);
        } else { 
                if (buf->x > 0)
                        if (curr_char(buf) == '\t') {
@@ -147,20 +148,18 @@ void screen_move_right(struct te_buffer *buf)
        if (prev_char(buf) == '\n') {
                screen_next_line(buf);
        } else { 
-               if (buf->x <= screen_line_length(buf->contents, buf->point)) {
                /* tab is the only character larger than 1 */
                        if (prev_char(buf) == '\t') {
                                buf->x += TAB_LEN;
                        } else {
                                buf->x++;
                        }
-               }
 
-               else { /* FIXME: scroll the screen instead of testing this
-                         condition
-                      */
-                       screen_next_line(buf);
-               }
+/*             else { /\* FIXME: scroll the screen instead of testing this */
+/*                       condition */
+/*                    *\/ */
+/*                     screen_next_line(buf); */
+/*             } */
        }
 
        move(buf->y, buf->x);
@@ -173,31 +172,28 @@ void screen_move_up(struct te_buffer *buf)
 
        int     i = 0;
        int     old_x = buf->x;
-       int curr_y;
-       int curr_x = 0;
-
-       /* move until the last character of the previous line (before the '\n')
-        * unless we're already there.
-        */
-       if (curr_char(buf) == '\n' && prev_char(buf) == '\n') {
-               /* special case for a blank line */
-               move_left(buf);
-               move_left(buf);
-       } else {
-               do {
-                       if(move_left(buf) == ERR)
-                               break;
-
-               } while(next_char(buf) != '\n');
-       }
+
+       /* move until the first character of the line */
+       do {
+               if(move_left(buf) == ERR)
+                       break;
+               
+       } while(prev_char(buf) != '\n');
+
+       /* then, move to the beginning of the previous line */
+       do {
+               if(move_left(buf) == ERR)
+                       break;
+               
+       } while(prev_char(buf) != '\n');
 
        screen_prev_line(buf);
-       
-       /* mimic emacs' behaviour of moving the user to the exact offset we were on */
+       buf->x = 0;
 
+       /* mimic emacs' behaviour of moving the user to the exact offset we were on */
                
-       while(buf->x > old_x && prev_char(buf) != '\n') {
-               screen_move_left(buf);
+       while(buf->x < old_x && next_char(buf) != '\n') {
+               screen_move_right(buf);
        }
 
        move(buf->y, buf->x);
@@ -211,8 +207,6 @@ void screen_move_down(struct te_buffer *buf)
 
        int     i = 0;
        int     old_x = buf->x;
-       int curr_y;
-       int curr_x = 0;
 
        do {
                /* move until the first char of the next line */
@@ -227,7 +221,6 @@ void screen_move_down(struct te_buffer *buf)
 
        while(buf->x < old_x && curr_char(buf) != '\n') {
                screen_move_right(buf);
-               statusprintf("curr_x : %d, old_x : %d", curr_x, old_x);
        }
 
        move(buf->y, buf->x);