From: Michael D. Lowis Date: Fri, 6 Apr 2018 12:45:13 +0000 (-0400) Subject: fixed cursor movement with arrow keys X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=d4d155f9cf55aaa1228d2527bcccaf6b3efbeda7;p=projs%2Ftide.git fixed cursor movement with arrow keys --- diff --git a/inc/edit.h b/inc/edit.h index 3fcecce..acd96e8 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -53,19 +53,14 @@ void buf_del(Buf* buf); void buf_undo(Buf* buf); void buf_redo(Buf* buf); -//void buf_loglock(Buf* buf); void buf_logclear(Buf* buf); void buf_lastins(Buf* buf); bool buf_iseol(Buf* buf, size_t pos); size_t buf_bol(Buf* buf, size_t pos); size_t buf_eol(Buf* buf, size_t pos); -//size_t buf_bow(Buf* buf, size_t pos); -//size_t buf_eow(Buf* buf, size_t pos); -//void buf_selline(Buf* buf); void buf_selword(Buf* buf, bool (*isword)(Rune)); -//void buf_selblock(Buf* buf, Rune beg, Rune end); void buf_selall(Buf* buf); void buf_selctx(Buf* buf, bool (*isword)(Rune)); @@ -154,7 +149,6 @@ void view_selectobj(View* view, bool (*istype)(Rune)); /* Command Executions *****************************************************************************/ - typedef struct Job Job; typedef void (*jobfn_t)(Job* job); diff --git a/lib/buf.c b/lib/buf.c index 7665010..222d238 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -12,6 +12,7 @@ static void log_clear(Log** list); static void syncgap(Buf* buf, size_t off); static int bytes_match(Buf* buf, size_t mbeg, size_t mend, char* str); static Rune nextrune(Buf* buf, size_t off, int move, bool (*testfn)(Rune)); +static void selline(Buf* buf); static void selblock(Buf* buf, Rune first, Rune last); void buf_init(Buf* buf) { @@ -251,24 +252,6 @@ size_t buf_eol(Buf* buf, size_t off) { return off; } -size_t buf_bow(Buf* buf, size_t off) { - for (; risword(buf_getrat(buf, off-1)); off--); - return off; -} - -size_t buf_eow(Buf* buf, size_t off) { - for (; risword(buf_getrat(buf, off)); off++); - return off; -} - -void buf_selline(Buf* buf) { - Sel sel = getsel(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; -} - void buf_selword(Buf* buf, bool (*isword)(Rune)) { Sel sel = getsel(buf); for (; isword(buf_getrat(buf, sel.beg-1)); sel.beg--); @@ -290,7 +273,7 @@ void buf_selctx(Buf* buf, bool (*isword)(Rune)) { else if (r == '{' || r == '}') selblock(buf, '{', '}'); else if (buf->selection.end == bol || r == '\n') - buf_selline(buf); + selline(buf); else if (risword(r)) buf_selword(buf, isword); else @@ -436,6 +419,14 @@ bool buf_insel(Buf* buf, size_t off) { /******************************************************************************/ +static void selline(Buf* buf) { + Sel sel = getsel(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; +} + static void selblock(Buf* buf, Rune first, Rune last) { Sel sel = getsel(buf); int balance = 0, dir; diff --git a/lib/view.c b/lib/view.c index 16b5fd8..3182eb2 100644 --- a/lib/view.c +++ b/lib/view.c @@ -298,7 +298,7 @@ static void move_selection(View* view, bool extsel, int move, movefn_t bything) if (bything == buf_byline) buf_setcol(BUF); if (!extsel) - buf_selclr(BUF, move); + buf_selclr(BUF, RIGHT); } /* only update column if not moving vertically */ if (bything != buf_byline)