diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2010-01-03 17:12:04 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2010-01-03 17:12:04 +0000 |
commit | 739b937b74547038615996749143a69f0707b0c0 (patch) | |
tree | ecb197a536c57adb1c691f90974b8d3be6ec277e /screen.c | |
parent | 7e4f8b45b64b0cbe889c5846806038c4c45c36e8 (diff) |
Fix selection behaviour when the cursor is moved backwards (ie so the selection
start is after the end).
Diffstat (limited to 'screen.c')
-rw-r--r-- | screen.c | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -234,11 +234,31 @@ screen_set_selection(struct screen *s, struct screen_sel *sel = &s->sel; memcpy(&sel->cell, gc, sizeof sel->cell); - sel->flag = 1; - if (ey < sy || (sy == ey && ex < sx)) { + + /* starting line < ending line -- downward selection. */ + if (sy < ey) { + sel->sx = sx; sel->sy = sy; + sel->ex = ex; sel->ey = ey; + return; + } + + /* starting line > ending line -- upward selection. */ + if (sy > ey) { + if (sx > 0) { + sel->sx = ex; sel->sy = ey; + sel->ex = sx - 1; sel->ey = sy; + } else { + sel->sx = ex; sel->sy = ey; + sel->ex = -1; sel->ey = sy - 1; + } + return; + } + + /* starting line == ending line. */ + if (ex < sx) { sel->sx = ex; sel->sy = ey; - sel->ex = sx; sel->ey = sy; + sel->ex = sx - 1; sel->ey = sy; } else { sel->sx = sx; sel->sy = sy; sel->ex = ex; sel->ey = ey; |