******************************************************************************/
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);
}
}