From 4acf721136e045087633335f30600768fe52bf51 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 21 Oct 2019 22:46:15 -0400 Subject: [PATCH] refactored cursor movement for selections --- src/lib/buf.c | 30 ++++++++++++++++++++++++++++-- src/lib/mouse.c | 1 - 2 files changed, 28 insertions(+), 3 deletions(-) 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) { -- 2.52.0