On 2014-06-06 22:47 +0100, Nicholas Marriott wrote:
> I'd rather fix the original bug in both modes, but if you want to
> change behaviour then do it only in vi mode.

OK, I've attached a patch which fixes the behavior for the vi mode and
also fixes the left key bug for the emacs mode. Please test both modes!

-- 
Balazs
>From 49b46f56046bf562e7de084fd6f580e4841e0fa1 Mon Sep 17 00:00:00 2001
From: Balazs Kezes <rlblas...@gmail.com>
Date: Sat, 7 Jun 2014 15:05:38 +0100
Subject: [PATCH] Fix the selection behavior bugs

The two bugs:
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.
---
 screen.c      | 23 ++++++++++++++++++-----
 tmux.h        |  1 +
 window-copy.c |  1 +
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/screen.c b/screen.c
index 7bfc015..d97e31b 100644
--- a/screen.c
+++ b/screen.c
@@ -277,6 +277,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);
@@ -326,16 +327,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->mode_keys == MODEKEY_EMACS)
+				xx = sel->sx-1;
+			else
+				xx = sel->sx;
+			if (py == sel->sy && px > xx)
 				return (0);
 		} else {
 			/* starting line == ending line. */
@@ -344,7 +353,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->mode_keys == 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 */
diff --git a/tmux.h b/tmux.h
index 1f80f41..27db059 100644
--- a/tmux.h
+++ b/tmux.h
@@ -756,6 +756,7 @@ LIST_HEAD(joblist, job);
 struct screen_sel {
 	int		 flag;
 	int		 rectflag;
+	int		 mode_keys; /* vim or emacs mode? */
 
 	u_int		 sx;
 	u_int		 sy;
diff --git a/window-copy.c b/window-copy.c
index ac29e6d..79bfe7d 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -195,6 +195,7 @@ window_copy_init(struct window_pane *wp)
 		s->mode |= MODE_MOUSE_STANDARD;
 
 	keys = options_get_number(&wp->window->options, "mode-keys");
+	s->sel.mode_keys = keys;
 	if (keys == MODEKEY_EMACS)
 		mode_key_init(&data->mdata, &mode_key_tree_emacs_copy);
 	else
-- 
2.0.0.526.g5318336

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their 
applications. Written by three acclaimed leaders in the field, 
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to