]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed cursor limit handling for movements
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 21 Apr 2018 02:36:47 +0000 (22:36 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 21 Apr 2018 02:36:47 +0000 (22:36 -0400)
lib/buf.c
lib/view.c
lib/x11.c

index 64c8385f1b21245f5c8975805e6bfd6d5c41991a..a5ebcd2b74138e423a63c60d4feb355b42698ded 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -295,9 +295,10 @@ void buf_selctx(Buf* buf, bool (*isword)(Rune)) {
 size_t buf_byrune(Buf* buf, size_t pos, int count) {
     int move = (count < 0 ? -1 : 1);
     count *= move; // remove the sign if there is one
-    for (; count > 0; count--)
-        if (pos > 0 || pos < buf_end(buf))
+    for (; count > 0; count--) {
+        if ((pos > 0 && move < 0) || (pos < buf_end(buf) && move > 0))
             pos += move;
+    }
     return pos;
 }
 
index 31485b0f911fd31a8763546775c480e05f17f3c9..b3463f152dfbb6f3925ddc7626cd1da9f343a87d 100644 (file)
@@ -163,14 +163,12 @@ void view_byline(View* view, int move, bool extsel) {
 void view_setcursor(View* view, size_t row, size_t col, bool extsel) {
     size_t i = 0, y = 0, idx = view->index + row;
     if (idx >= view->nrows) return;
-    printf("row: %ld %ld\n", row, idx);
     Row* selrow = view->rows[idx];
     for (; i < selrow->len; i++) {
         y += selrow->cols[i].width;
         if (col < y) break;
     }
-    getsel(view)->end = selrow[i].off;
-    printf("clicked: %ld\n", getsel(view)->end);
+    getsel(view)->end = selrow->cols[i].off;
 }
 
 void view_selword(View* view, size_t row, size_t col) {
index 74a7105659069343579dad8b49873c56c1736d1d..6106b882c3a4c5b565df651a2b891d95eab11fc6 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -285,23 +285,6 @@ static void draw_rect(int color, int x, int y, int width, int height) {
     XftColorFree(X.display, X.visual, X.colormap, &clr);
 }
 
-static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t len) {
-    XftGlyphSpec specs[len];
-    for (size_t i = 0; i < len; i++) {
-        int rune = glyphs[i].rune;
-        if (rune == '\r' || rune == '\n' ||  rune == '\t')
-            rune = ' ';
-        specs[i].glyph = XftCharIndex(X.display, X.font, rune);
-        specs[i].x = x;
-        specs[i].y = y + X.font->ascent;
-        x += glyphs[i].width;
-    }
-    XftColor fgc;
-    xftcolor(&fgc, EditFg);
-    XftDrawGlyphSpec(X.xft, &fgc, X.font, specs, len);
-    XftColorFree(X.display, X.visual, X.colormap, &fgc);
-}
-
 static void draw_view(int i, size_t nrows, drawcsr* csr, int bg, int fg, int sel) {
     size_t fwidth = font_width();
     size_t fheight = X.font->height;
@@ -313,15 +296,24 @@ static void draw_view(int i, size_t nrows, drawcsr* csr, int bg, int fg, int sel
     draw_rect(bg, csr->x, csr->y, csr->w, (nrows * fheight) + 9);
     for (size_t i = 0; i < nrows; i++) {
         Row* row = view_getrow(view, i + view->index);
-        draw_glyphs(csr->x + 2, csr->y + 2 + (i * fheight), row->cols, row->len);
-    }
-    /* place the cursor on screen */
-    if (!view_selsize(view) && csrx != SIZE_MAX && csry != SIZE_MAX) {
-        draw_rect(
-            (i == TAGS ? TagsCsr : EditCsr),
-            csr->x + 2 + (csrx * fwidth),
-            csr->y + 2 + (csry * fheight),
-            1, fheight);
+        size_t x = (csr->x + 2), y = (csr->y + 2 + (i * fheight));
+        XftGlyphSpec specs[row->len];
+        for (size_t i = 0; i < row->len; i++) {
+            int rune = row->cols[i].rune;
+            if (rune == '\r' || rune == '\n' ||  rune == '\t')
+                rune = ' ';
+            if (row->cols[i].off == view->buffer.selection.end)
+                draw_rect((i == TAGS ? TagsCsr : EditCsr), x, y, 1, fheight);
+            specs[i].glyph = XftCharIndex(X.display, X.font, rune);
+            specs[i].x = x;
+            specs[i].y = y + X.font->ascent;
+            x += row->cols[i].width;
+        }
+        XftColor fgc;
+        xftcolor(&fgc, EditFg);
+        XftDrawGlyphSpec(X.xft, &fgc, X.font, specs, row->len);
+        XftColorFree(X.display, X.visual, X.colormap, &fgc);
+
     }
     csr->y += (nrows * fheight) + 3;
 }