From 1d7a05a24521cca24f78705921673dfe673efd0b Mon Sep 17 00:00:00 2001 From: khamidou Date: Fri, 4 Dec 2009 08:05:01 +0100 Subject: [PATCH] fixed a bug : when the file didn\'t finish with a \\n, the last line was printed two times --- README | 2 +- buffer.c | 13 ++++++++++--- screen.c | 8 ++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README b/README index eff196e..852cfc3 100644 --- a/README +++ b/README @@ -3,4 +3,4 @@ Te, a text 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 \ No newline at end of file +that has been left still since the 70's. The Great Rock'n roll swindle ! \ No newline at end of file diff --git a/buffer.c b/buffer.c index a60de7a..2a0b306 100644 --- a/buffer.c +++ b/buffer.c @@ -129,17 +129,24 @@ 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; + 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); - if (e_offset == BSTR_ERR) + if (e_offset == BSTR_ERR) { e_offset = blength(b); + } - if (s_offset == 0) /* the first line of the file */ + if (s_offset == 0) /* the first line of the file */ return bmidstr(b, s_offset, e_offset - s_offset); - else + else if (e_offset == blength(b)) { + return bmidstr(b, s_offset + 1, e_offset + 1 - s_offset); + } + else /* otherwise, skip the first '\n' character */ return bmidstr(b, s_offset + 1, e_offset - s_offset); } diff --git a/screen.c b/screen.c index 3d03f81..260ef5b 100644 --- a/screen.c +++ b/screen.c @@ -58,13 +58,14 @@ void paint_buffer_nlines(struct te_buffer *buf, int nlines) for(i = 0; i < nlines; i++) { s = current_line_as_bstring(buf->contents, count); draw_line(s, i); - count += blength(s); + count += blength(s) + 1; bdestroy(s); if (count >= blength(buf->contents)) break; } - + + miniprintf("count %d", count); restoreyx(); refresh(); @@ -192,6 +193,9 @@ void screen_next_line(struct te_buffer *buf) else { scroll_up(buffer_win); bstring s = current_line_as_bstring(buf->contents, buf->point - 1); + if (biseq(bfromcstr(""), s)) + return; + draw_line(s, LINES - 4); bdestroy(s); -- 2.43.0