From: khamidou Date: Thu, 25 Feb 2010 20:46:53 +0000 (+0100) Subject: fixed this backspace bug X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=7b071d33c361611c097b8f24a484591415836b7b;p=te.git fixed this backspace bug --- diff --git a/README b/README index a11266a..ad0ed3a 100644 --- a/README +++ b/README @@ -2,5 +2,8 @@ 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. 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 +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. +Building +======== + +type 'make' in the te directory to build the te executable. \ No newline at end of file diff --git a/buffer.c b/buffer.c index b9e7795..b828f69 100644 --- a/buffer.c +++ b/buffer.c @@ -254,6 +254,7 @@ void insert_char(struct te_buffer *buf, char c) return; binsertch(buf->contents, buf->point, 1, c); + buf->dirty = 1; return; } @@ -264,6 +265,8 @@ void delete_char(struct te_buffer *buf) bdelete(buf->contents, buf->point, 1); move_left(buf); + buf->dirty = 1; + return; } diff --git a/keyb.c b/keyb.c index 19a3e8a..22d5815 100644 --- a/keyb.c +++ b/keyb.c @@ -16,10 +16,10 @@ void input_loop(void) refresh(); -/* miniprintf("%c, line length: %d, y: %d, x%d", */ -/* (bchar(current_buf->contents, current_buf->point) == '\n') ? 'N' : bchar(current_buf->contents, current_buf->point), */ -/* screen_line_length(current_buf->contents, current_buf->point), */ -/* current_buf->y, current_buf->x); */ + miniprintf("%c, line length: %d, y: %d, x%d", + (bchar(current_buf->contents, current_buf->point) == '\n') ? 'N' : bchar(current_buf->contents, current_buf->point), + screen_line_length(current_buf->contents, current_buf->point), + current_buf->y, current_buf->x); } @@ -61,6 +61,7 @@ void process_command(int c) break; case 'i': + case 0x1B: /* escape */ case KEY_END: /* switch between command and input mode */ command_mode = 0; @@ -102,7 +103,8 @@ void process_input(int c) case KEY_UP: screen_move_up(current_buf); break; - + + case 0x1B: /* escape */ case KEY_END: command_mode = 1; miniprintf("-- COMMAND --"); diff --git a/screen.c b/screen.c index 130fa7b..41d1f9b 100644 --- a/screen.c +++ b/screen.c @@ -35,6 +35,12 @@ void cleanup_windows(void) endwin(); } +void pause(void) +{ + /* used for debugging purposes */ + getch(); +} + void paint_buffer(struct te_buffer *buf) { paint_buffer_nlines(buf, LINES - 2); @@ -338,7 +344,7 @@ void screen_insert_char(struct te_buffer *buf, char c) if (c == '\n') { clrtoeol(); - clear_nfirst_lines(buffer_win, buf->y - 1); + clear_nfirst_lines(buffer_win, max(buf->y - 1, 0)); scroll_down(buffer_win); paint_buffer_nlines(buf, buf->y + 1); paint_nthline(buf, buf->y + 2, buf->y + 1); @@ -356,31 +362,28 @@ void screen_delete_char(struct te_buffer *buf) return; move_left(buf); - bstring s = current_line_as_bstring(buf->contents, max(buf->point - 1, 0)); + bstring previous_line = current_line_as_bstring(buf->contents, max(buf->point - 1, 0)); char c = curr_char(buf); delete_char(buf); - - - buf->dirty = 1; + bstring s = current_line_as_bstring(buf->contents, max(buf->point, 0)); 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, max(buf->y - 1, 0)); + clear_nfirst_lines(buffer_win, max(buf->y, 0)); scroll_up(buffer_win); paint_buffer_nlines(buf, buf->y + 1); -// screen_prev_line(buf); screen_prev_line(buf); - buf->x = screen_line_length(s, 0); + buf->x = max(screen_line_length(previous_line, 0) - 1, 0); /* max because scr_l_len("a") == 1 and coords begin at 0 */ + move(buf->y, buf->x); } else { - bstring s = current_line_as_bstring(buf->contents, buf->point - 1); draw_line(s, buf->y); screen_move_left(buf); move_right(buf); /* yes it's ugly but I don't feel like recoding screen_move_right atm */ } + bdestroy(previous_line); + bdestroy(s); } void screen_switch_buffer(struct te_buffer *buf)