]> git.mdlowis.com Git - projs/tide.git/commitdiff
reworked buf_setcol interface
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 3 Apr 2018 01:26:36 +0000 (21:26 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 3 Apr 2018 01:26:36 +0000 (21:26 -0400)
inc/edit.h
lib/buf.c
lib/view.c

index 4d947d2bd502d1677b6e84bc6aee4c97727a9dd4..313e25b64883e0c21afcd4099a7bc9c564ee711e 100644 (file)
@@ -85,7 +85,7 @@ void buf_findstr(Buf* buf, int dir, char* str, size_t* beg, size_t* end);
 size_t buf_setln(Buf* buf, size_t line);
 size_t buf_getln(Buf* buf, size_t off);
 void buf_getcol(Buf* buf, Sel* p_sel);
-size_t buf_setcol(Buf* buf, size_t pos, size_t col);
+void buf_setcol(Buf* buf, Sel* p_sel);
 
 /* Screen management functions
  *****************************************************************************/
index d00e391bc8c80f7df0f011419eebbe9a949647ac..37206a0a0190b1986a1ecfd26e19eada864e31be 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -436,22 +436,20 @@ void buf_getcol(Buf* buf, Sel* sel) {
         sel->col += runewidth(sel->col, buf_getrat(buf, curr));
 }
 
-size_t buf_setcol(Buf* buf, size_t pos, size_t col) {
-    size_t bol = buf_bol(buf, pos);
+void buf_setcol(Buf* buf, Sel* sel) {
+    size_t bol = buf_bol(buf, sel->end);
     size_t curr = bol, len = 0, i = 0;
     /* determine the length of the line in columns */
     for (; !buf_iseol(buf, curr); curr++)
         len += runewidth(len, buf_getrat(buf, curr));
     /* iterate over the runes until we reach the target column */
-    curr = bol, i = 0;
-    while (i < col && i < len) {
-        int width = runewidth(i, buf_getrat(buf, curr));
-        curr = buf_byrune(buf, curr, 1);
-        if (col >= i && col < (i+width))
+    for (sel->end = bol, i = 0; i < sel->col && i < len;) {
+        int width = runewidth(i, buf_getrat(buf, sel->end));
+        sel->end = buf_byrune(buf, sel->end, 1);
+        if (sel->col >= i && sel->col < (i + width))
             break;
         i += width;
     }
-    return curr;
 }
 
 static int rune_match(Buf* buf, size_t mbeg, size_t mend, Rune* runes) {
index 40a8ba369a53e04eff6c62c7d571f0483a77d3f2..53c367a139456aa7a1c8e1d8a975b0ce80e94bc7 100644 (file)
@@ -330,7 +330,7 @@ static void move_selection(View* view, bool extsel, Sel* sel, int move, movefn_t
     } else {
         sel->end = bything(&(view->buffer), sel->end, move);
         if (bything == buf_byline)
-            sel->end = buf_setcol(&(view->buffer), sel->end, sel->col);
+            buf_setcol(&(view->buffer), &(view->selection));
         if (!extsel) sel->beg = sel->end;
     }
     /* only update column if not moving vertically */