From: Michael D. Lowis Date: Tue, 3 Apr 2018 01:26:36 +0000 (-0400) Subject: reworked buf_setcol interface X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=2bd04f57e5e8e5f89c12698227735ed7cdf01eb2;p=projs%2Ftide.git reworked buf_setcol interface --- diff --git a/inc/edit.h b/inc/edit.h index 4d947d2..313e25b 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -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 *****************************************************************************/ diff --git a/lib/buf.c b/lib/buf.c index d00e391..37206a0 100644 --- 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) { diff --git a/lib/view.c b/lib/view.c index 40a8ba3..53c367a 100644 --- a/lib/view.c +++ b/lib/view.c @@ -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 */