]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed bug in column tracking
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 3 Apr 2018 18:23:33 +0000 (14:23 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 3 Apr 2018 18:23:33 +0000 (14:23 -0400)
lib/buf.c
lib/view.c

index 6e364a65069e4eddfb46fc52391009b1f1eed1f7..0aa20fd9d24e8fe521b2cb7cb4d84843d79302f2 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -410,12 +410,14 @@ void buf_setln(Buf* buf, Sel* sel, size_t line) {
 }
 
 void buf_getcol(Buf* buf, Sel* sel) {
+    if (!sel) sel = &(buf->selection);
     size_t pos = sel->end, curr = buf_bol(buf, pos);
     for (sel->col = 0; curr < pos; curr = buf_byrune(buf, curr, 1))
         sel->col += runewidth(sel->col, buf_getrat(buf, curr));
 }
 
 void buf_setcol(Buf* buf, Sel* sel) {
+    if (!sel) sel = &(buf->selection);
     size_t bol = buf_bol(buf, sel->end);
     size_t curr = bol, len = 0, i = 0;
     /* determine the length of the line in columns */
index da63780c3f1bbd1136d867a4d851db927d956b6c..059d69ba537a5c5d444472a526d395b6d476c7de 100644 (file)
@@ -5,7 +5,7 @@
 
 typedef size_t (*movefn_t)(Buf* buf, size_t pos, int count);
 
-static void move_selection(View* view, bool extsel, Sel* sel, int move, movefn_t bything);
+static void move_selection(View* view, bool extsel, int move, movefn_t bything);
 static void move_to(View* view, bool extsel, size_t off);
 static void select_context(View* view, bool (*isword)(Rune), Sel* sel);
 static bool selection_visible(View* view);
@@ -97,15 +97,15 @@ Row* view_getrow(View* view, size_t row) {
 }
 
 void view_byrune(View* view, int move, bool extsel) {
-    move_selection(view, extsel, getsel(view), move, buf_byrune);
+    move_selection(view, extsel, move, buf_byrune);
 }
 
 void view_byword(View* view, int move, bool extsel) {
-    move_selection(view, extsel, getsel(view), move, buf_byword);
+    move_selection(view, extsel, move, buf_byword);
 }
 
 void view_byline(View* view, int move, bool extsel) {
-    move_selection(view, extsel, getsel(view), move, buf_byline);
+    move_selection(view, extsel, move, buf_byline);
 }
 
 void view_setcursor(View* view, size_t row, size_t col, bool extsel) {
@@ -289,19 +289,20 @@ void view_selectobj(View* view, bool (*istype)(Rune)) {
     view->sync_needed = true;
 }
 
-static void move_selection(View* view, bool extsel, Sel* sel, int move, movefn_t bything) {
+static void move_selection(View* view, bool extsel, int move, movefn_t bything) {
     view->sync_needed = true;
-    if (buf_selsz(&(view->buffer), sel) && !extsel) {
-        buf_selclr(&(view->buffer), sel, move);
+    if (buf_selsz(&(view->buffer), NULL) && !extsel) {
+        buf_selclr(&(view->buffer), NULL, move);
     } else {
+        Sel* sel = getsel(view);
         sel->end = bything(&(view->buffer), sel->end, move);
         if (bything == buf_byline)
             buf_setcol(&(view->buffer), getsel(view));
-        if (!extsel) buf_selclr(&(view->buffer), sel, RIGHT);
+        if (!extsel) buf_selclr(&(view->buffer), sel, move);
     }
     /* only update column if not moving vertically */
     if (bything != buf_byline)
-        buf_getcol(&(view->buffer), getsel(view));
+        buf_getcol(&(view->buffer), NULL);
 }
 
 static void move_to(View* view, bool extsel, size_t off) {