]> git.mdlowis.com Git - projs/tide.git/commitdiff
renamed Dot* to Sel in preparation for a new selection management module
authorMike Lowis <mike.lowis@gentex.com>
Tue, 25 Oct 2016 20:25:11 +0000 (16:25 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Tue, 25 Oct 2016 20:25:11 +0000 (16:25 -0400)
edit.h
keyboard.c
mouse.c
screen.c
tests/tests.c
xedit.c

diff --git a/edit.h b/edit.h
index 10556641089dd2a2d5fa6c589a4d5628a47a38be..b4262f821240d6d90cbaee2e39c4072ba0b8c268 100644 (file)
--- a/edit.h
+++ b/edit.h
@@ -249,8 +249,8 @@ enum ColorScheme {
 extern enum ColorScheme ColorBase;
 extern Buf Buffer;
 extern unsigned TargetCol;
-extern unsigned DotBeg;
-extern unsigned DotEnd;
+extern unsigned SelBeg;
+extern unsigned SelEnd;
 
 /* Configuration
  *****************************************************************************/
index d2c8453871e5367255b605afbc973f3a8939e1b7..3012a041acb4859013dda1cac007087fc890a169 100644 (file)
@@ -5,42 +5,42 @@ static void toggle_colors(void) {
 }
 
 static void cursor_up(void) {
-    DotBeg = DotEnd = buf_byline(&Buffer, DotEnd, -1);
-    DotBeg = DotEnd = buf_setcol(&Buffer, DotEnd, TargetCol);
+    SelBeg = SelEnd = buf_byline(&Buffer, SelEnd, -1);
+    SelBeg = SelEnd = buf_setcol(&Buffer, SelEnd, TargetCol);
 }
 
 static void cursor_dn(void) {
-    DotBeg = DotEnd = buf_byline(&Buffer, DotEnd, 1);
-    DotBeg = DotEnd = buf_setcol(&Buffer, DotEnd, TargetCol);
+    SelBeg = SelEnd = buf_byline(&Buffer, SelEnd, 1);
+    SelBeg = SelEnd = buf_setcol(&Buffer, SelEnd, TargetCol);
 }
 
 static void cursor_left(void) {
-    DotBeg = DotEnd = buf_byrune(&Buffer, DotEnd, -1);
-    TargetCol = buf_getcol(&Buffer, DotEnd);
+    SelBeg = SelEnd = buf_byrune(&Buffer, SelEnd, -1);
+    TargetCol = buf_getcol(&Buffer, SelEnd);
 }
 
 static void cursor_right(void) {
-    DotBeg = DotEnd = buf_byrune(&Buffer, DotEnd, 1);
-    TargetCol = buf_getcol(&Buffer, DotEnd);
+    SelBeg = SelEnd = buf_byrune(&Buffer, SelEnd, 1);
+    TargetCol = buf_getcol(&Buffer, SelEnd);
 }
 
 static void cursor_bol(void) {
-    DotBeg = DotEnd = buf_bol(&Buffer, DotEnd);
+    SelBeg = SelEnd = buf_bol(&Buffer, SelEnd);
     TargetCol = 0;
 }
 
 static void cursor_eol(void) {
-    DotBeg = DotEnd = buf_eol(&Buffer, DotEnd);
+    SelBeg = SelEnd = buf_eol(&Buffer, SelEnd);
     TargetCol = (unsigned)-1;
 }
 
 static void insert_before(void) {
-    DotEnd = DotBeg;
+    SelEnd = SelBeg;
     Buffer.insert_mode = true;
 }
 
 static void insert_after(void) {
-    DotBeg = ++DotEnd;
+    SelBeg = ++SelEnd;
     Buffer.insert_mode = true;
 }
 
@@ -63,15 +63,15 @@ static void quit(void) {
 }
 
 static void dot_delete(void) {
-    if (DotEnd == buf_end(&Buffer)) return;
-    size_t n = DotEnd - DotBeg;
+    if (SelEnd == buf_end(&Buffer)) return;
+    size_t n = SelEnd - SelBeg;
     bool insert = Buffer.insert_mode;
     if (!insert || !n) n++;
     Buffer.insert_mode = true;
     for (size_t i = 0; i < n; i++)
-        buf_del(&Buffer, DotBeg);
-    DotEnd = DotBeg;
-    TargetCol = buf_getcol(&Buffer, DotEnd);
+        buf_del(&Buffer, SelBeg);
+    SelEnd = SelBeg;
+    TargetCol = buf_getcol(&Buffer, SelEnd);
     Buffer.insert_mode = insert;
 }
 
@@ -81,17 +81,17 @@ static void dot_change(void) {
 }
 
 static void dot_backspace(void) {
-    if (DotBeg > 0 && DotBeg == DotEnd) DotBeg--;
-    while (DotBeg < DotEnd)
-        buf_del(&Buffer, --DotEnd);
-    TargetCol = buf_getcol(&Buffer, DotEnd);
+    if (SelBeg > 0 && SelBeg == SelEnd) SelBeg--;
+    while (SelBeg < SelEnd)
+        buf_del(&Buffer, --SelEnd);
+    TargetCol = buf_getcol(&Buffer, SelEnd);
 }
 
 static void insert(Rune r) {
     if (!Buffer.insert_mode) return;
-    buf_ins(&Buffer, DotEnd++, r);
-    DotBeg = DotEnd;
-    TargetCol = buf_getcol(&Buffer, DotEnd);
+    buf_ins(&Buffer, SelEnd++, r);
+    SelBeg = SelEnd;
+    TargetCol = buf_getcol(&Buffer, SelEnd);
 }
 
 /*****************************************************************************/
diff --git a/mouse.c b/mouse.c
index 1cceaa451c82db7a4390bc29127d63bdc5d280d5..615c62571792e3fffd4274210c27c361f03d589e 100644 (file)
--- a/mouse.c
+++ b/mouse.c
@@ -7,71 +7,72 @@ void unused(MouseEvent* mevnt) {
 
 void move_cursor(MouseEvent* mevnt) {
     if (mevnt->y == 0) return;
-    DotBeg = DotEnd = screen_getoff(&Buffer, DotEnd, mevnt->y-1, mevnt->x);
-    TargetCol = buf_getcol(&Buffer, DotEnd);
+    SelBeg = SelEnd = screen_getoff(&Buffer, SelEnd, mevnt->y-1, mevnt->x);
+    TargetCol = buf_getcol(&Buffer, SelEnd);
 }
 
 void bigword(MouseEvent* mevnt) {
     (void)mevnt;
-    unsigned mbeg = DotEnd, mend = DotEnd;
+    unsigned mbeg = SelEnd, mend = SelEnd;
     for (; !isblank(buf_get(&Buffer, mbeg-1)); mbeg--);
     for (; !isblank(buf_get(&Buffer, mend)); mend++);
-    DotBeg = mbeg, DotEnd = mend-1;
+    SelBeg = mbeg, SelEnd = mend-1;
 }
 
 void selection(MouseEvent* mevnt) {
     (void)mevnt;
-    unsigned bol = buf_bol(&Buffer, DotEnd);
-    Rune r = buf_get(&Buffer, DotEnd);
-    if (DotEnd == bol || r == '\n' || r == RUNE_CRLF) {
-        DotBeg = bol;
-        DotEnd = buf_eol(&Buffer, DotEnd);
+    unsigned bol = buf_bol(&Buffer, SelEnd);
+    Rune r = buf_get(&Buffer, SelEnd);
+    if (SelEnd == bol || r == '\n' || r == RUNE_CRLF) {
+        SelBeg = bol;
+        SelEnd = buf_eol(&Buffer, SelEnd);
     } else if (isword(r)) {
-        DotBeg = buf_bow(&Buffer, DotEnd);
-        DotEnd = buf_eow(&Buffer, DotEnd);
-        if (Buffer.insert_mode) DotEnd++;
+        SelBeg = buf_bow(&Buffer, SelEnd);
+        SelEnd = buf_eow(&Buffer, SelEnd);
+        if (Buffer.insert_mode) SelEnd++;
     } else if (r == '(' || r == ')') {
-        DotBeg = buf_lscan(&Buffer, DotEnd, '(');
-        DotEnd = buf_rscan(&Buffer, DotEnd, ')');
-        if (Buffer.insert_mode) DotEnd++;
+        SelBeg = buf_lscan(&Buffer, SelEnd, '(');
+        SelEnd = buf_rscan(&Buffer, SelEnd, ')');
+        if (Buffer.insert_mode) SelEnd++;
     } else if (r == '[' || r == ']') {
-        DotBeg = buf_lscan(&Buffer, DotEnd, '[');
-        DotEnd = buf_rscan(&Buffer, DotEnd, ']');
-        if (Buffer.insert_mode) DotEnd++;
+        SelBeg = buf_lscan(&Buffer, SelEnd, '[');
+        SelEnd = buf_rscan(&Buffer, SelEnd, ']');
+        if (Buffer.insert_mode) SelEnd++;
     } else if (r == '{' || r == '}') {
-        DotBeg = buf_lscan(&Buffer, DotEnd, '{');
-        DotEnd = buf_rscan(&Buffer, DotEnd, '}');
-        if (Buffer.insert_mode) DotEnd++;
+        SelBeg = buf_lscan(&Buffer, SelEnd, '{');
+        SelEnd = buf_rscan(&Buffer, SelEnd, '}');
+        if (Buffer.insert_mode) SelEnd++;
     } else {
         bigword(mevnt);
     }
 }
 
 void search(MouseEvent* mevnt) {
-    unsigned clickpos = screen_getoff(&Buffer, DotEnd, mevnt->y-1, mevnt->x);
-    if (clickpos < DotBeg || clickpos > DotEnd) {
+    unsigned clickpos = screen_getoff(&Buffer, SelEnd, mevnt->y-1, mevnt->x);
+    if (clickpos < SelBeg || clickpos > SelEnd) {
         move_cursor(mevnt);
         selection(mevnt);
+    } else {
+        buf_find(&Buffer, &SelBeg, &SelEnd);
     }
-    buf_find(&Buffer, &DotBeg, &DotEnd);
     unsigned x, y;
-    screen_update(&Buffer, DotEnd, &x, &y);
+    screen_update(&Buffer, SelEnd, &x, &y);
     extern void move_pointer(unsigned x, unsigned y);
     move_pointer(x, y);
+
 }
 
 void scrollup(MouseEvent* mevnt) {
     (void)mevnt;
-    DotBeg = DotEnd = buf_byline(&Buffer, DotEnd, -ScrollLines);
+    SelBeg = SelEnd = buf_byline(&Buffer, SelEnd, -ScrollLines);
 }
 
 void scrolldn(MouseEvent* mevnt) {
     (void)mevnt;
-    DotBeg = DotEnd = buf_byline(&Buffer, DotEnd, ScrollLines);
+    SelBeg = SelEnd = buf_byline(&Buffer, SelEnd, ScrollLines);
 }
 
 /*****************************************************************************/
-
 enum {
     SINGLE_CLICK = 0,
     DOUBLE_CLICK,
@@ -129,8 +130,8 @@ static void handle_click(MouseEvent* mevnt) {
 
 static void handle_drag(MouseEvent* mevnt) {
     if (mevnt->y == 0 || mevnt->button != MOUSE_LEFT) return;
-    DotEnd = screen_getoff(&Buffer, DotEnd, mevnt->y-1, mevnt->x);
-    TargetCol = buf_getcol(&Buffer, DotEnd);
+    SelEnd = screen_getoff(&Buffer, SelEnd, mevnt->y-1, mevnt->x);
+    TargetCol = buf_getcol(&Buffer, SelEnd);
 }
 
 void handle_mouse(MouseEvent* mevnt) {
index cb084cbe9df2ae0e0071c3233b5cc978fb90fc7e..5cd464b7f55c9cc664ef166d83ffed9ef815d59b 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -11,7 +11,7 @@ static unsigned fill_row(Buf* buf, unsigned row, unsigned pos) {
     screen_getrow(row)->off = pos;
     screen_clearrow(row);
     for (unsigned x = 0; x < NumCols;) {
-        uint32_t attr = (DotBeg <= pos && pos < DotEnd ? ATTR_SELECTED : ATTR_NORMAL);
+        uint32_t attr = (SelBeg <= pos && pos < SelEnd ? ATTR_SELECTED : ATTR_NORMAL);
         Rune r = buf_get(buf, pos++);
         x += screen_setcell(row, x, attr, r);
         if (buf_iseol(buf, pos-1)) break;
index 0ed3712a54f174a19294f2c751bce878dd5fbcdb..d2e8f0a0b24b0e1620abec7ec677d95d9980e205 100644 (file)
@@ -5,8 +5,8 @@
 Buf Buffer;
 unsigned CursorPos;
 unsigned TargetCol;
-unsigned DotBeg;
-unsigned DotEnd;
+unsigned SelBeg;
+unsigned SelEnd;
 enum ColorScheme ColorBase;
 
 void move_pointer(unsigned x, unsigned y) {
diff --git a/xedit.c b/xedit.c
index 0e4f28283b5fa24e8b3815e2b5fc4ca558015df1..2d2f3df77f3ab870ebcba93e5cd1891e3faeaa3d 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -9,8 +9,8 @@
 
 Buf Buffer;
 unsigned TargetCol = 0;
-unsigned DotBeg = 0;
-unsigned DotEnd = 0;
+unsigned SelBeg = 0;
+unsigned SelEnd = 0;
 enum ColorScheme ColorBase = DEFAULT_COLORSCHEME;
 XftColor Palette[CLR_COUNT][2];
 struct {
@@ -395,7 +395,7 @@ static void redraw(void) {
 
     /* update the screen buffer and retrieve cursor coordinates */
     unsigned csrx, csry;
-    screen_update(&Buffer, DotEnd, &csrx, &csry);
+    screen_update(&Buffer, SelEnd, &csrx, &csry);
 
     /* flush the screen buffer */
     unsigned nrows, ncols;