]> khamidou — GitHub mirrors - te.git/commitdiff
fixed a erase-char bug
authorkhamidou <khamidou@gmail.com>
Tue, 8 Dec 2009 20:51:44 +0000 (21:51 +0100)
committerkhamidou <khamidou@gmail.com>
Tue, 8 Dec 2009 20:51:44 +0000 (21:51 +0100)
README
buffer.c
buffer.h
screen.c

diff --git a/README b/README
index 81d15289f250999c190d827c401d7c4cfd28ad3d..a11266a022a1882a164de25aef360f4bd76dcaff 100644 (file)
--- 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
index 3dd39f527c78d6aaab43cb42639edbac9f156c5b..b9e77954ae57997330776936472d15b05d2aeff0 100644 (file)
--- 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.
  */
index 4fabc5b8d013cc7bad72881278461918fe03a639..03d5c8d067aa7799ba462c8f6eccd2e424c77243 100644 (file)
--- 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);
index be9d38a477083e8b6a60ea4614411bc06d84486b..130fa7b60b261ed05e3db3005749dafa33965274 100644 (file)
--- 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);