]> git.mdlowis.com Git - projs/tide.git/commitdiff
refactored cursor movement for selections
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 22 Oct 2019 02:46:15 +0000 (22:46 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 22 Oct 2019 02:46:15 +0000 (22:46 -0400)
src/lib/buf.c
src/lib/mouse.c

index c7b209f5650c0132285ae77ab654a2ce58274629..097ff4eeadbef43c95acb6fa826ab1e6c82c9010 100644 (file)
@@ -844,7 +844,23 @@ static size_t moveby(int bything, Buf* buf, size_t pos, int count)
 
 void buf_selmove(Buf* buf, bool extsel, int move, int bything)
 {
-    buf->selection.end = moveby(bything, buf, buf->selection.end, move);
+    (void)bything, (void)moveby, (void)extsel;
+
+    if (buf_selsz(buf) && !extsel)
+    {
+        if (move < 0)
+        {
+            buf->selection.end = moveby(bything, buf, buf_selbeg(buf), move);
+        }
+        else if (!buf_isbol(buf, buf->selection.end))
+        {
+            buf->selection.end = moveby(bything, buf, buf_selend(buf), move);
+        }
+    }
+    else
+    {
+        buf->selection.end = moveby(bything, buf, buf->selection.end, move);
+    }
 
     if (bything == BY_LINE)
     {
@@ -857,7 +873,17 @@ void buf_selmove(Buf* buf, bool extsel, int move, int bything)
 
     if (!extsel)
     {
-        buf->selection.beg = buf->selection.end;
+        Sel sel = selget(buf);
+        /* collapse the selection */
+        if (move > 0)
+        {
+            sel.beg = sel.end;
+        }
+        else
+        {
+            sel.end = sel.beg;
+        }
+        buf->selection = sel;
     }
 }
 
index 8bd04efdd6eeead38297408f4b2c9fddf5f1a807..f5d6aed9ea4ca64ced8a9223cdb106fcffef7dab 100644 (file)
@@ -93,7 +93,6 @@ static int mouse_right(bool pressed)
 
 int process_mouse(int btn, bool pressed)
 {
-    require(btn <= MouseWheelDn);
     int ret = MouseActNone;
     switch(btn)
     {