]> git.mdlowis.com Git - projs/tide.git/commitdiff
changed column updating api
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 3 Apr 2018 01:09:59 +0000 (21:09 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 3 Apr 2018 01:09:59 +0000 (21:09 -0400)
inc/edit.h
lib/buf.c
lib/view.c

index 9c9c5e3ef6c94893ea0583b87b99bb803bb6ce59..4d947d2bd502d1677b6e84bc6aee4c97727a9dd4 100644 (file)
@@ -84,7 +84,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);
-size_t buf_getcol(Buf* buf, size_t pos);
+void buf_getcol(Buf* buf, Sel* p_sel);
 size_t buf_setcol(Buf* buf, size_t pos, size_t col);
 
 /* Screen management functions
index 4710f4fc8e5e633676e5866296bafc5176bfa149..d00e391bc8c80f7df0f011419eebbe9a949647ac 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -430,11 +430,10 @@ size_t buf_getln(Buf* buf, size_t off) {
     return line;
 }
 
-size_t buf_getcol(Buf* buf, size_t pos) {
-    size_t col = 0, curr = buf_bol(buf, pos);
-    for (; curr < pos; curr = buf_byrune(buf, curr, 1))
-        col += runewidth(col, buf_getrat(buf, curr));
-    return col;
+void buf_getcol(Buf* buf, Sel* sel) {
+    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));
 }
 
 size_t buf_setcol(Buf* buf, size_t pos, size_t col) {
index b67e0b4fa8ca4595e0aceffded910b019f4aeec7..40a8ba369a53e04eff6c62c7d571f0483a77d3f2 100644 (file)
@@ -335,7 +335,7 @@ static void move_selection(View* view, bool extsel, Sel* sel, int move, movefn_t
     }
     /* only update column if not moving vertically */
     if (bything != buf_byline)
-        sel->col = buf_getcol(&(view->buffer), sel->end);
+        buf_getcol(&(view->buffer), &(view->selection));
 }
 
 static void move_to(View* view, bool extsel, size_t off) {
@@ -343,7 +343,7 @@ static void move_to(View* view, bool extsel, size_t off) {
     view->selection.end = (off > buf_end(buf) ? buf_end(buf) : off);
     if (!extsel)
         view->selection.beg = view->selection.end;
-    view->selection.col = buf_getcol(&(view->buffer), view->selection.end);
+    buf_getcol(&(view->buffer), &(view->selection));
     view->sync_needed = true;
 }
 
@@ -366,7 +366,7 @@ static void select_context(View* view, bool (*isword)(Rune), Sel* sel) {
         buf_getword(buf, risbigword, sel);
     }
     sel->end = buf_byrune(&(view->buffer), sel->end, RIGHT);
-    sel->col = buf_getcol(&(view->buffer), sel->end);
+    buf_getcol(&(view->buffer), &(view->selection));
 }
 
 static void selswap(Sel* sel) {