From 29d20a55b645600feca1b54a13333e598336dad2 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 11 Aug 2014 22:18:16 +0000 Subject: Fix two copy mode problems: 1. In vi mode the selection doesn't include the last character if you moved the cursor up or left. 2. In emacs mode the selection includes the last character if you moved the cursor to the left. From Balazs Kezes. --- screen.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'screen.c') diff --git a/screen.c b/screen.c index 2b0e9fba..3e7d9924 100644 --- a/screen.c +++ b/screen.c @@ -276,6 +276,7 @@ int screen_check_selection(struct screen *s, u_int px, u_int py) { struct screen_sel *sel = &s->sel; + u_int xx; if (!sel->flag) return (0); @@ -325,16 +326,24 @@ screen_check_selection(struct screen *s, u_int px, u_int py) if (py < sel->sy || py > sel->ey) return (0); - if ((py == sel->sy && px < sel->sx) - || (py == sel->ey && px > sel->ex)) + if (py == sel->sy && px < sel->sx) + return 0; + + if (py == sel->ey && px > sel->ex) return (0); } else if (sel->sy > sel->ey) { /* starting line > ending line -- upward selection. */ if (py > sel->sy || py < sel->ey) return (0); - if ((py == sel->sy && px >= sel->sx) - || (py == sel->ey && px < sel->ex)) + if (py == sel->ey && px < sel->ex) + return (0); + + if (sel->modekeys == MODEKEY_EMACS) + xx = sel->sx - 1; + else + xx = sel->sx; + if (py == sel->sy && px > xx) return (0); } else { /* starting line == ending line. */ @@ -343,7 +352,11 @@ screen_check_selection(struct screen *s, u_int px, u_int py) if (sel->ex < sel->sx) { /* cursor (ex) is on the left */ - if (px > sel->sx || px < sel->ex) + if (sel->modekeys == MODEKEY_EMACS) + xx = sel->sx - 1; + else + xx = sel->sx; + if (px > xx || px < sel->ex) return (0); } else { /* selection start (sx) is on the left */ -- cgit From 4e956d545a52fe6b8310cfb30a26a89976d55cd9 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 1 Sep 2014 21:50:18 +0000 Subject: Various minor style and spacing nits. --- screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'screen.c') diff --git a/screen.c b/screen.c index 3e7d9924..703f3e10 100644 --- a/screen.c +++ b/screen.c @@ -327,7 +327,7 @@ screen_check_selection(struct screen *s, u_int px, u_int py) return (0); if (py == sel->sy && px < sel->sx) - return 0; + return (0); if (py == sel->ey && px > sel->ex) return (0); -- cgit