From 1a2d1f5c54bf0dd211818eb109f8544050aad575 Mon Sep 17 00:00:00 2001 From: khamidou Date: Tue, 8 Dec 2009 21:51:44 +0100 Subject: [PATCH] fixed a erase-char bug --- README | 7 ++++--- buffer.c | 11 +++++++++++ buffer.h | 1 + screen.c | 39 ++++++++++++++++++++++++++------------- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/README b/README index 81d1528..a11266a 100644 --- a/README +++ b/README @@ -1,5 +1,6 @@ -Te, a textawq editor +Te, a text editor ================= -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 +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. I'm not really proud of it but it works. +I have to say that this is not everyone's text editor. \ No newline at end of file diff --git a/buffer.c b/buffer.c index 3dd39f5..b9e7795 100644 --- a/buffer.c +++ b/buffer.c @@ -104,6 +104,17 @@ int line_length(bstring b, int point) */ } +/* How many chars are there between 0 and X ? */ +int screen_numchar_to_offset(bstring s, int x) +{ + int i = 0; + + for (i = 0; i < x; i++) + if (bchar(s, i) == '\t') + i += TAB_LEN; + else + i += 1; +} /* The length of a line as displayed on the screen. */ diff --git a/buffer.h b/buffer.h index 4fabc5b..03d5c8d 100644 --- a/buffer.h +++ b/buffer.h @@ -30,6 +30,7 @@ struct te_buffer* load_buffer(char *filename); void init_buffers(void); int line_length(bstring b, int point); +int screen_numchar_to_offset(bstring s, int x); int screen_line_length(bstring b, int point); bstring current_line_as_bstring(bstring b, int point); int prev_char(struct te_buffer *buf); diff --git a/screen.c b/screen.c index be9d38a..130fa7b 100644 --- a/screen.c +++ b/screen.c @@ -3,11 +3,9 @@ #include "util.h" #include "keyb.h" -static int scr_y, scr_x; - -#define saveyx() getyx(stdscr, scr_y, scr_x) -#define restoreyx() move(scr_y, scr_x) +#define saveyx() { int scr_y, scr_x; getyx(stdscr, scr_y, scr_x); do { } while(0) +#define restoreyx() move(scr_y, scr_x); } do { } while(0) void init_windows(void) { @@ -116,20 +114,25 @@ void draw_line(bstring s, int y) saveyx(); move(y, 0); clrtoeol(); - + /* FIXME : wrap line if we go beyond COLS */ for (i = 0; i < blength(s); i++) { + if (i == COLS - 1) { + mvwaddch(buffer_win, y, screen_abs, '\\'); + goto bail_out; + return; + } + if (bchar(s, i) == '\t') { for (j = 0; j < TAB_LEN; j++) mvwaddch(buffer_win, y, screen_abs++, ' '); - } else if (i == COLS - 1) { - mvwaddch(buffer_win, y, screen_abs, '\\'); - screen_next_line(current_buf); - } else { + } else { mvwaddch(buffer_win, y, screen_abs, bchar(s, i)); screen_abs++; } } + +bail_out: restoreyx(); } @@ -241,6 +244,17 @@ int screen_move_right(struct te_buffer *buf) } else { buf->x++; } + + if(buf->x == COLS - 1) { + bstring s = current_line_as_bstring(buf->contents, buf->point); + int off = screen_numchar_to_offset(s, COLS - 1); + bstring s2 = bmidstr(s, off, blength(s) - off); + draw_line(s2, buf->y); + bdestroy(s); + bdestroy(s2); + wmove(buffer_win, buf->y, 0); + refresh(); + } } move(buf->y, buf->x); @@ -345,16 +359,15 @@ void screen_delete_char(struct te_buffer *buf) bstring s = current_line_as_bstring(buf->contents, max(buf->point - 1, 0)); char c = curr_char(buf); delete_char(buf); - move_right(buf); - if (buf->dirty < 1) - buf->dirty = 1; + + buf->dirty = 1; if (c == '\n') { bstring s2 = current_line_as_bstring(buf->contents, max(buf->point - blength(s), 0)); statusprintf("s : %s", bstr2cstr(s, '\0')); clrtoeol(); - clear_nfirst_lines(buffer_win, buf->y); + clear_nfirst_lines(buffer_win, max(buf->y - 1, 0)); scroll_up(buffer_win); paint_buffer_nlines(buf, buf->y + 1); // screen_prev_line(buf); -- 2.43.0