From: Michael D. Lowis Date: Tue, 3 Apr 2018 01:09:59 +0000 (-0400) Subject: changed column updating api X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=b23b363513a07ac2e37b7a424a08dffdcb247d0a;p=projs%2Ftide.git changed column updating api --- diff --git a/inc/edit.h b/inc/edit.h index 9c9c5e3..4d947d2 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -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 diff --git a/lib/buf.c b/lib/buf.c index 4710f4f..d00e391 100644 --- 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) { diff --git a/lib/view.c b/lib/view.c index b67e0b4..40a8ba3 100644 --- a/lib/view.c +++ b/lib/view.c @@ -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) {