From: Michael D. Lowis Date: Sat, 19 Oct 2019 03:15:17 +0000 (-0400) Subject: checkpoint commit X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c0e1a1922fbe0bea0448b510342efb1a3eaf83a1;p=projs%2Ftide.git checkpoint commit --- diff --git a/TODO.md b/TODO.md index e3525b2..e04e325 100644 --- a/TODO.md +++ b/TODO.md @@ -4,6 +4,7 @@ ## STAGING +* tide: refactor selection handling and column tracking out of view.c * all: eliminate multiple return statements and other lint * tide: byrune, byword, byline functions should be hidden in buf.c * tide: column tracking should be hidden in buf.c diff --git a/src/lib/buf.c b/src/lib/buf.c index 7ee3da5..ba42c20 100644 --- a/src/lib/buf.c +++ b/src/lib/buf.c @@ -41,6 +41,13 @@ static Sel selget(Buf* buf) return (sel.end < sel.beg ? selswap(sel) : sel); } +static void selset(Buf* buf, Sel sel) +{ + buf->selection = sel; + buf_getcol(buf); +} + + static void putch(Buf* buf, char b, Sel* p_sel) { if (b != '\r') @@ -159,7 +166,7 @@ static void trim_whitespace(Buf* buf) { sel = selswap(sel); } - buf->selection = sel; + selset(buf, sel); } int buf_save(Buf* buf, char* path) @@ -337,7 +344,7 @@ static void selline(Buf* buf) sel.beg = buf_bol(buf, sel.end); sel.end = buf_eol(buf, sel.end); sel.end = buf_byrune(buf, sel.end, RIGHT); - buf->selection = sel; + selset(buf, sel); } static void selblock(Buf* buf, Rune first, Rune last) @@ -530,7 +537,6 @@ void buf_selctx(Buf* buf, bool (*isword)(Rune)) { selline(buf); } - else if (selquote(buf, '"') || selquote(buf, '`') || selquote(buf, '\'')) { ; /* condition performs selection */ @@ -777,7 +783,7 @@ void buf_selln(Buf* buf) sel.end = buf_eol(buf, sel.end); sel.end = buf_byrune(buf, sel.end, RIGHT); } - buf->selection = sel; + selset(buf, sel); } void buf_selclr(Buf* buf, int dir) @@ -792,7 +798,7 @@ void buf_selclr(Buf* buf, int dir) { sel.end = sel.beg; } - buf->selection = sel; + selset(buf, sel); } bool buf_insel(Buf* buf, size_t off) diff --git a/src/lib/view.c b/src/lib/view.c index c1d8678..10990cc 100644 --- a/src/lib/view.c +++ b/src/lib/view.c @@ -33,7 +33,6 @@ static void move_selection(View* view, bool extsel, int move, movefn_t bything) if (buf_selsz(BUF) && !extsel) { buf_selclr(BUF, move); - buf_getcol(BUF); if (bything == buf_byline) { CSRPOS = bything(BUF, CSRPOS, move); @@ -56,12 +55,6 @@ static void move_selection(View* view, bool extsel, int move, movefn_t bything) { buf_selclr(BUF, (move < 0 ? LEFT : RIGHT)); } - - /* only update column if not moving vertically */ - if (bything != buf_byline) - { - buf_getcol(BUF); - } } }