]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed a bug in snapping selection to covered lines
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 27 Sep 2018 13:20:36 +0000 (09:20 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 27 Sep 2018 13:20:36 +0000 (09:20 -0400)
tide.c

diff --git a/tide.c b/tide.c
index d5ae95b284278bcd284312205f777d090161e4a9..5b4277b8f01bd0e82bdc2a2ae301fb809e5dcc8f 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -101,18 +101,18 @@ void exec(char* cmd) {
  ******************************************************************************/
 static void select_line(char* arg) {
     Buf* buf = win_buf(FOCUSED);
-    if (buf->selection.beg <= buf->selection.end) {
-        buf->selection.beg = buf_bol(buf, buf->selection.beg);
-        if (!buf_iseol(buf, buf->selection.end)) {
-            buf->selection.end = buf_eol(buf, buf->selection.end);
-            buf->selection.end = buf_byrune(buf, buf->selection.end, RIGHT);
-        }
-    } else {
-        if (!buf_iseol(buf, buf->selection.beg)) {
-            buf->selection.beg = buf_eol(buf, buf->selection.beg);
-            buf->selection.beg = buf_byrune(buf, buf->selection.beg, RIGHT);
-        }
-        buf->selection.end = buf_bol(buf, buf->selection.end);
+    /* swap the direction of the selection so beg < end */
+    if (buf->selection.beg > buf->selection.end) {
+        size_t off = buf->selection.beg;
+        buf->selection.beg = buf->selection.end;
+        buf->selection.end = off;
+    }
+
+    /* Expand the selection to completely select the lines covered */
+    buf->selection.beg = buf_bol(buf, buf->selection.beg);
+    if (!buf_iseol(buf, buf->selection.end-1)) {
+        buf->selection.end = buf_eol(buf, buf->selection.end);
+        buf->selection.end = buf_byrune(buf, buf->selection.end, RIGHT);
     }
 }