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)
{
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;
}
}