]> khamidou — GitHub mirrors - te.git/commitdiff
actually, this commit fixes the bug
authorkhamidou <khamidou@gmail.com>
Fri, 4 Dec 2009 18:25:33 +0000 (19:25 +0100)
committerkhamidou <khamidou@gmail.com>
Fri, 4 Dec 2009 18:25:33 +0000 (19:25 +0100)
README
buffer.c
buffer.h
screen.c

diff --git a/README b/README
index 852cfc323e772f75d2613ed96593d31cbb2a4a5b..81d15289f250999c190d827c401d7c4cfd28ad3d 100644 (file)
--- a/README
+++ b/README
@@ -1,6 +1,5 @@
-Te, a text editor
+Te, a textawq editor
 =================
 
-
-This is the readme for te, a small text editor that tries to bring some innovation into a field
-that has been left still since the 70's. The Great Rock'n roll swindle !
\ No newline at end of file
+This is the readme for te, a small text editor thatsqs tries to bring some innovation into a field
+that has been left still since the 70's. I'm not really proud of it but it works.The Great Rock'n roll swindle !
\ No newline at end of file
index 2a0b30629d43595620389770e051aa9b37bd3fdb..3dd39f527c78d6aaab43cb42639edbac9f156c5b 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -129,25 +129,29 @@ int screen_line_length(bstring b, int point)
 
 bstring current_line_as_bstring(bstring b, int point)
 {
-       if (point > blength(b) - 1)
-               point = blength(b) - 1;
+       if (point > blength(b))
+               point = blength(b);
 
        int s_offset = bstrrchrp(b, '\n', max(point, 0));
        if (s_offset == BSTR_ERR)
                s_offset = 0;
 
-       int e_offset = bstrchrp(b, '\n', point + 1);
+       int e_offset = bstrchrp(b, '\n', max(point + 1, 0));
        if (e_offset == BSTR_ERR) {
                e_offset = blength(b);
        }
 
        if (s_offset == 0)      /* the first line of the file */
-               return bmidstr(b, s_offset, e_offset - s_offset);
-       else if (e_offset == blength(b)) {
-               return bmidstr(b, s_offset + 1, e_offset + 1 - s_offset);
+               return bmidstr(b, 0, e_offset);
+/*     else if (e_offset == blength(b)) { */
+               
+/*             return bmidstr(b, s_offset + 1, e_offset + 1 - s_offset); */
+
+/*     } */
+       else    {               /* otherwise, skip the first '\n' character */
+               bstring s1 = bmidstr(b, s_offset + 1, e_offset - s_offset);
+               return s1;
        }
-       else                    /* otherwise, skip the first '\n' character */
-               return bmidstr(b, s_offset + 1, e_offset - s_offset);
 }
 
 /*
@@ -269,3 +273,13 @@ void write_buffer(struct te_buffer *buf)
        free(c);
 }
 
+/*
+  Is the point in the last line ?
+*/
+int is_last_line(bstring s, int point)
+{
+       if (bstrchrp(s, '\n', max(point, 0)) == BSTR_ERR)
+               return TRUE;
+       else
+               return FALSE;
+}
index 974b96a4f9b7bf9892fde20bf16c6926f5845e9b..4fabc5b8d013cc7bad72881278461918fe03a639 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -39,5 +39,6 @@ int                           move_right(struct te_buffer *buf);
 int                            move_left(struct te_buffer *buf);
 void                           insert_char(struct te_buffer *buf, char c);
 void                           delete_char(struct te_buffer *buf);
+int                            is_last_line(bstring s, int point);
 
 #endif
index 260ef5b6a7160fb8a88fa112d991e786ae40c144..be9d38a477083e8b6a60ea4614411bc06d84486b 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -53,19 +53,18 @@ void paint_buffer_nlines(struct te_buffer *buf, int nlines)
 
        bstring s;
        int i = 0;
-       int count = buf->top_char;
+       int count = max(buf->top_char - 1, 0);
 
        for(i = 0; i < nlines; i++) {
                s = current_line_as_bstring(buf->contents, count);
                draw_line(s, i);
-               count += blength(s) + 1;
-
+               count += blength(s);
                bdestroy(s);
-               if (count >= blength(buf->contents))
+
+               if (is_last_line(buf->contents, count) == TRUE)
                    break;
        }
 
-       miniprintf("count %d", count);
        restoreyx();
        refresh();
 
@@ -123,13 +122,7 @@ void draw_line(bstring s, int y)
                if (bchar(s, i) == '\t') {
                        for (j = 0; j < TAB_LEN; j++)
                                mvwaddch(buffer_win, y, screen_abs++, ' ');
-               }
-/*             else if (bchar(s, i) == '\n') { */
-/*                             mvwaddstr(buffer_win, y, screen_abs++, "\\n"); */
-/*                             screen_abs++; */
-/*                             mvwaddch(buffer_win, y, screen_abs++, '\n'); */
-               /*              } */ 
-               else if (i == COLS - 1) {
+               } else if (i == COLS - 1) {
                        mvwaddch(buffer_win, y, screen_abs, '\\');
                        screen_next_line(current_buf);
                } else {