]> git.mdlowis.com Git - projs/tide.git/commitdiff
refactored selection handling to handle cursor
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 12 Oct 2018 02:53:52 +0000 (22:53 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 12 Oct 2018 02:53:52 +0000 (22:53 -0400)
TODO.md
inc/edit.h
src/lib/buf.c
src/tide.c

diff --git a/TODO.md b/TODO.md
index d8c172cd25bd3258361c0bd3706b11b8af4d055f..23460792f61ab18b5f966b95771b4122603426f2 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -7,6 +7,9 @@
 * implement tctl command
 * gap buffer does not handle UTF-8 currently
 * Line - Get the current line number(s) containing the selection
+
+## UNCERTAIN
+
 * refactor selection handling to avoid swapping manually (use buf_selbeg and buf_selend)
 * encode EOL setting in log entries?
 * centering logic in view.c seems slightly broken
index 1780a169620d15a1d2b53c018f2558a019e3bb7e..1e838c8138a83eb33470490d06b9a7b7205a17b3 100644 (file)
@@ -75,6 +75,7 @@ void buf_getcol(Buf* buf);
 void buf_setcol(Buf* buf);
 
 size_t buf_selbeg(Buf* buf);
+size_t buf_selend(Buf* buf);
 size_t buf_selsz(Buf* buf);
 void buf_selln(Buf* buf);
 void buf_selclr(Buf* buf, int dir);
index 735f63db5de71c7bec9442efdfaf464287092011..32a4669acc3e3ad9a8ccc3d3a3ca1481c1dbf528 100644 (file)
@@ -644,25 +644,25 @@ size_t buf_selbeg(Buf* buf) {
     return (sel.beg < sel.end ? sel.beg : sel.end);
 }
 
+size_t buf_selend(Buf* buf) {
+    Sel sel = buf_getsel(buf);
+    return (sel.beg < sel.end ? sel.end : sel.beg);
+}
+
 size_t buf_selsz(Buf* buf) {
     Sel sel = buf_getsel(buf);
     return sel.end - sel.beg;
 }
 
 void buf_selln(Buf* buf) {
-    /* 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->selection.beg) {
-        buf->selection.end = buf_eol(buf, buf->selection.end);
-        buf->selection.end = buf_byrune(buf, buf->selection.end, RIGHT);
+    Sel sel = (Sel){ .beg = buf_selbeg(buf), .end = buf_selend(buf) };
+    sel.beg = buf_bol(buf, sel.beg);
+    if (!buf_iseol(buf, sel.end-1) || sel.end == sel.beg) {
+        sel.end = buf_eol(buf, sel.end);
+        sel.end = buf_byrune(buf, sel.end, RIGHT);
     }
+    buf->selection = sel;
 }
 
 void buf_selclr(Buf* buf, int dir) {
index e324ba8b28a047ce4a464cf57f6338710da789a9..30de94f49d238b441a24c3df1089b26398882bda 100644 (file)
@@ -339,7 +339,6 @@ static void goto_ctag(char* arg) {
     char* str = view_getctx(win_view(FOCUSED));
     jump_to(str);
     free(str);
-
 }
 
 static void tabs(char* arg) {