]> khamidou — GitHub mirrors - te.git/commitdiff
fixed this backspace bug
authorkhamidou <khamidou@gmail.com>
Thu, 25 Feb 2010 20:46:53 +0000 (21:46 +0100)
committerkhamidou <khamidou@gmail.com>
Thu, 25 Feb 2010 20:46:53 +0000 (21:46 +0100)
README
buffer.c
keyb.c
screen.c

diff --git a/README b/README
index a11266a022a1882a164de25aef360f4bd76dcaff..ad0ed3a5dd79de07418b5e9303ee1a0a66c8a0d6 100644 (file)
--- 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
index b9e77954ae57997330776936472d15b05d2aeff0..b828f6991d7e78e717dab51eb984b064ae6317d1 100644 (file)
--- 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 19a3e8ab14fbe2fb86f4db90d3568af6bc3be8f8..22d58153a19d427f0fbb0ee398607de0c56219c6 100644 (file)
--- 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 --");
index 130fa7b60b261ed05e3db3005749dafa33965274..41d1f9b6bc701b18beb587bbce2798d995597d66 100644 (file)
--- 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)