From 823d60f1a9e524b18b2ede6b520ba83d0a920884 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 3 Apr 2018 14:23:33 -0400 Subject: [PATCH] fixed bug in column tracking --- lib/buf.c | 2 ++ lib/view.c | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/buf.c b/lib/buf.c index 6e364a6..0aa20fd 100644 --- 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 */ diff --git a/lib/view.c b/lib/view.c index da63780..059d69b 100644 --- a/lib/view.c +++ b/lib/view.c @@ -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) { -- 2.52.0