From 371f2138ee1840222b34c056bb112a9526d17045 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 11 Aug 2014 22:18:16 +0000 Subject: [PATCH] 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. --- usr.bin/tmux/screen.c | 25 +++++++++++++++++++------ usr.bin/tmux/tmux.h | 3 ++- usr.bin/tmux/window-copy.c | 3 ++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/usr.bin/tmux/screen.c b/usr.bin/tmux/screen.c index 8a571b30e5e..e3b47610c0a 100644 --- a/usr.bin/tmux/screen.c +++ b/usr.bin/tmux/screen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen.c,v 1.27 2014/01/09 14:05:55 nicm Exp $ */ +/* $OpenBSD: screen.c,v 1.28 2014/08/11 22:18:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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 */ diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 949e082927b..60e5689c30f 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.468 2014/08/11 22:14:30 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.469 2014/08/11 22:18:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -794,6 +794,7 @@ LIST_HEAD(joblist, job); struct screen_sel { int flag; int rectflag; + int modekeys; u_int sx; u_int sy; diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 0e0d1ee3bd1..a99aace9514 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.111 2014/06/19 07:37:59 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.112 2014/08/11 22:18:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -199,6 +199,7 @@ window_copy_init(struct window_pane *wp) mode_key_init(&data->mdata, &mode_key_tree_emacs_copy); else mode_key_init(&data->mdata, &mode_key_tree_vi_copy); + s->sel.modekeys = keys; data->backing = NULL; -- 2.20.1