From: Michael D. Lowis Date: Thu, 27 Sep 2018 13:20:36 +0000 (-0400) Subject: fixed a bug in snapping selection to covered lines X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=3bf0276c902fa2cb2f0ced8dc2c1c46aca95ef0d;p=projs%2Ftide.git fixed a bug in snapping selection to covered lines --- diff --git a/tide.c b/tide.c index d5ae95b..5b4277b 100644 --- a/tide.c +++ b/tide.c @@ -101,18 +101,18 @@ void exec(char* cmd) { ******************************************************************************/ static void select_line(char* arg) { Buf* buf = win_buf(FOCUSED); - if (buf->selection.beg <= buf->selection.end) { - buf->selection.beg = buf_bol(buf, buf->selection.beg); - if (!buf_iseol(buf, buf->selection.end)) { - buf->selection.end = buf_eol(buf, buf->selection.end); - buf->selection.end = buf_byrune(buf, buf->selection.end, RIGHT); - } - } else { - if (!buf_iseol(buf, buf->selection.beg)) { - buf->selection.beg = buf_eol(buf, buf->selection.beg); - buf->selection.beg = buf_byrune(buf, buf->selection.beg, RIGHT); - } - buf->selection.end = buf_bol(buf, buf->selection.end); + /* swap the direction of the selection so beg < end */ + if (buf->selection.beg > buf->selection.end) { + size_t off = buf->selection.beg; + buf->selection.beg = buf->selection.end; + buf->selection.end = off; + } + + /* Expand the selection to completely select the lines covered */ + buf->selection.beg = buf_bol(buf, buf->selection.beg); + if (!buf_iseol(buf, buf->selection.end-1)) { + buf->selection.end = buf_eol(buf, buf->selection.end); + buf->selection.end = buf_byrune(buf, buf->selection.end, RIGHT); } }