From: khamidou Date: Fri, 4 Dec 2009 18:25:33 +0000 (+0100) Subject: actually, this commit fixes the bug X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=9b72538f178a71a9181981aa3d30bef0741ad3e8;p=te.git actually, this commit fixes the bug --- diff --git a/README b/README index 852cfc3..81d1528 100644 --- 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 diff --git a/buffer.c b/buffer.c index 2a0b306..3dd39f5 100644 --- 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; +} diff --git a/buffer.h b/buffer.h index 974b96a..4fabc5b 100644 --- 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 diff --git a/screen.c b/screen.c index 260ef5b..be9d38a 100644 --- 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 {