From: Michael D. Lowis Date: Tue, 22 Oct 2019 02:46:15 +0000 (-0400) Subject: refactored cursor movement for selections X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=4acf721136e045087633335f30600768fe52bf51;p=projs%2Ftide.git refactored cursor movement for selections --- diff --git a/src/lib/buf.c b/src/lib/buf.c index c7b209f..097ff4e 100644 --- a/src/lib/buf.c +++ b/src/lib/buf.c @@ -844,7 +844,23 @@ static size_t moveby(int bything, Buf* buf, size_t pos, int count) void buf_selmove(Buf* buf, bool extsel, int move, int bything) { - buf->selection.end = moveby(bything, buf, buf->selection.end, move); + (void)bything, (void)moveby, (void)extsel; + + if (buf_selsz(buf) && !extsel) + { + if (move < 0) + { + buf->selection.end = moveby(bything, buf, buf_selbeg(buf), move); + } + else if (!buf_isbol(buf, buf->selection.end)) + { + buf->selection.end = moveby(bything, buf, buf_selend(buf), move); + } + } + else + { + buf->selection.end = moveby(bything, buf, buf->selection.end, move); + } if (bything == BY_LINE) { @@ -857,7 +873,17 @@ void buf_selmove(Buf* buf, bool extsel, int move, int bything) if (!extsel) { - buf->selection.beg = buf->selection.end; + Sel sel = selget(buf); + /* collapse the selection */ + if (move > 0) + { + sel.beg = sel.end; + } + else + { + sel.end = sel.beg; + } + buf->selection = sel; } } diff --git a/src/lib/mouse.c b/src/lib/mouse.c index 8bd04ef..f5d6aed 100644 --- a/src/lib/mouse.c +++ b/src/lib/mouse.c @@ -93,7 +93,6 @@ static int mouse_right(bool pressed) int process_mouse(int btn, bool pressed) { - require(btn <= MouseWheelDn); int ret = MouseActNone; switch(btn) {