]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added offset tracking per line in the screen buffer. Also moved the rune to display...
authorMike Lowis <mike.lowis@gentex.com>
Tue, 4 Oct 2016 20:26:27 +0000 (16:26 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Tue, 4 Oct 2016 20:26:27 +0000 (16:26 -0400)
edit.h
screen.c
xedit.c

diff --git a/edit.h b/edit.h
index 3173a73aad77cb2c8d60badd5f594a7b626a811a..9126b525bcaf58eaecf380b22a0a82e8c0bdf647 100644 (file)
--- a/edit.h
+++ b/edit.h
@@ -56,6 +56,8 @@ unsigned buf_byline(Buf* buf, unsigned pos, int count);
 /* Screen management functions
  *****************************************************************************/
 typedef struct {
+    unsigned off;
+    unsigned rlen;
     unsigned len;
     Rune cols[];
 } Row;
@@ -65,7 +67,8 @@ void screen_getsize(unsigned* nrows, unsigned* ncols);
 void screen_clear(void);
 Row* screen_getrow(unsigned row);
 void screen_clearrow(unsigned row);
-void screen_setcell(unsigned row, unsigned col, Rune r);
+void screen_setrowoff(unsigned row, unsigned off);
+unsigned screen_setcell(unsigned row, unsigned col, Rune r);
 Rune screen_getcell(unsigned row, unsigned col);
 
 /* Miscellaneous Functions
index 33818ada55c02aedcffddf26da468d3af37e8eb8..27f1fb98e11733abe83f312f4fc2c48ae41f4c2b 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -36,16 +36,32 @@ void screen_clearrow(unsigned row)
     if (!scrrow) return;
     for (unsigned i = 0; i < NumCols; i++)
         scrrow->cols[i] = (Rune)' ';
-    scrrow->len = 0;
+    scrrow->rlen = 0;
+    scrrow->len  = 0;
 }
 
-void screen_setcell(unsigned row, unsigned col, Rune r)
+void screen_setrowoff(unsigned row, unsigned off)
 {
-    if (row >= NumRows || col >= NumCols) return;
+    screen_getrow(row)->off = off;
+}
+
+unsigned screen_setcell(unsigned row, unsigned col, Rune r)
+{
+    if (row >= NumRows || col >= NumCols) return 0;
     Row* scrrow = screen_getrow(row);
-    scrrow->cols[col] = r;
-    if (col+1 >= scrrow->len)
-        scrrow->len = col+1;
+    /* write the rune to the screen buf */
+    unsigned ncols = 1;
+    if (r == '\t') {
+        scrrow->cols[col] = ' ';
+        ncols = (TabWidth - (col % TabWidth));
+    } else if (r != '\n') {
+        scrrow->cols[col] = r;
+    }
+    /* Update lengths */
+    scrrow->rlen += 1;
+    if ((col + ncols) > scrrow->len)
+        scrrow->len = col + ncols;
+    return ncols;
 }
 
 Rune screen_getcell(unsigned row, unsigned col)
diff --git a/xedit.c b/xedit.c
index 807109504aa1746aebf61c374281846463490bf0..c7a4ffad8f54b7570cbf0c95fbe35388e8a77ee7 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -247,19 +247,14 @@ static void redraw(void) {
     screen_clearrow(0);
     for (unsigned y = 1; y < nrows; y++) {
         screen_clearrow(y);
-        for (unsigned x = 0; x < ncols; x++) {
+        screen_setrowoff(y, pos);
+        for (unsigned x = 0; x < ncols;) {
             if (CursorPos == pos)
                 csrx = x, csry = y;
             Rune r = buf_get(&Buffer, pos++);
-            if (r == '\n') {
-                screen_setcell(y,x,' ');
-                break;
-            } else if (r == '\t') {
-                screen_setcell(y,x,' ');
-                x += TabWidth - (x % TabWidth) - 1;
-            } else {
-                screen_setcell(y,x,r);
-            }
+            unsigned cols = screen_setcell(y,x,r);
+            x += cols;
+            if (r == '\n') break;
         }
     }
     EndPos = pos-1;
@@ -272,8 +267,7 @@ static void redraw(void) {
     /* flush the screen buffer */
     for (unsigned y = 0; y < nrows; y++) {
         Row* row = screen_getrow(y);
-        if (row->len > 0)
-            XftDrawString32(X.xft, &txtclr, X.font, 0, (y+1) * fheight, (FcChar32*)(row->cols), (row->len));
+        XftDrawString32(X.xft, &txtclr, X.font, 0, (y+1) * fheight, (FcChar32*)(row->cols), (row->len));
     }
 
     /* Place cursor on screen */
@@ -281,9 +275,7 @@ static void redraw(void) {
     if (InsertMode) {
         XftDrawRect(X.xft, &csrclr, csrx * fwidth, csry * fheight + X.font->descent, 2, fheight);
     } else {
-        unsigned width = 1;
-        if ('\t' == buf_get(&Buffer, CursorPos))
-            width = TabWidth - (csrx % TabWidth);
+        unsigned width = ('\t' == buf_get(&Buffer, CursorPos) ? (TabWidth - (csrx % TabWidth)) : 1);
         XftDrawRect(X.xft, &csrclr, csrx * fwidth, csry * fheight + X.font->descent, width * fwidth, fheight);
         XftDrawString32(X.xft, &bkgclr, X.font, csrx * fwidth, (csry+1) * fheight, (FcChar32*)&csrrune, 1);
     }