]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed logic for fixing user selection when whitespace is deleted
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 26 Sep 2018 19:38:21 +0000 (15:38 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 26 Sep 2018 19:38:21 +0000 (15:38 -0400)
lib/buf.c

index c11617723448511ee80a7e5b40b5db1e45fb1818..e6d95d5055488feccfa30f8e53fe14f7c502a741 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -153,16 +153,15 @@ static void trim_whitespace(Buf* buf) {
         /* If we reached a newline, then delete whatever we have selected */
         if (r == '\r' || r == '\n') {
             buf->selection.beg = buf_byrune(buf, buf->selection.beg, +1);
+            Sel del = buf->selection;
+            sel.beg -= (del.beg < sel.beg ? (min(del.end, sel.beg) - del.beg) : 0);
+            sel.end -= (del.beg < sel.end ? (min(del.end, sel.end) - del.beg) : 0);
             buf_del(buf);
         }
 
         /* if current char is not whitespace, then shrink the selection */               
-        if (r != ' ' && r != '\t') {
+        if (r != ' ' && r != '\t')
             buf->selection.beg = buf->selection.end;
-        } else {
-            if (buf->selection.end <= sel.beg) sel.beg--;
-            if (buf->selection.end <= sel.end) sel.end--;
-        }
 
         /* move to the next character */
         prev = buf->selection.end;