summaryrefslogtreecommitdiffstats
path: root/xterm-keys.c
diff options
context:
space:
mode:
authornicm <nicm>2017-05-07 21:25:59 +0000
committernicm <nicm>2017-05-07 21:25:59 +0000
commitd52f579fd5e7fd21d7dcf837780cbf98498b10ce (patch)
tree1ac52bc56e5fa341bd4d7555fd2f4c8de917eae3 /xterm-keys.c
parent2fef10b9ac926de223e0e88b2d77489e983f62e5 (diff)
Up to now, tmux sees \033\033[OA as M-Up and since we turned on
xterm-keys by default, generates \033[1;3A instead of \033\033[OA. Unfortunately this confuses vi, which doesn't understand xterm keys and now sees Escape+Up pressed within escape-time as Escape followed by A. The issue doesn't happen in xterm itself because it gets the keys from X and can distinguish between a genuine M-Up and Escape+Up. Because xterm can, tmux can too: xterm will give us \033[1;3A (that is, kUP3) for a real M-Up and \033\033OA for Escape+Up - in fact, we can be sure any \033 preceding an xterm key is a real Escape key press because Meta would be part of the xterm key instead of a separate \033. So change tmux to recognise both sequences as M-Up for its own purposes, but generate the xterm version of M-Up only if it originally received the xterm version from the terminal. This means we will return to sending \033\033OA instead of the xterm key for terminals that do not support xterm keys themselves, but there is no practical way around this because they do not allow us to distinguish between Escape+Up and M-Up. xterm style escape sequences are now the de facto standard for these keys in any case. Problem reported by jsing@ and subsequently by Cecile Tonglet in GitHub issue 907.
Diffstat (limited to 'xterm-keys.c')
-rw-r--r--xterm-keys.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/xterm-keys.c b/xterm-keys.c
index 5ffc845f..b10c10db 100644
--- a/xterm-keys.c
+++ b/xterm-keys.c
@@ -197,7 +197,7 @@ xterm_keys_find(const char *buf, size_t len, size_t *size, key_code *key)
if (matched == -1)
continue;
if (matched == 0)
- *key = entry->key | modifiers;
+ *key = (entry->key|modifiers|KEYC_XTERM);
return (matched);
}
return (-1);
@@ -227,8 +227,16 @@ xterm_keys_lookup(key_code key)
if (modifiers == 1)
return (NULL);
+ /*
+ * If this has the escape modifier, but was not originally an xterm
+ * key, it may be a genuine escape + key. So don't pass it through as
+ * an xterm key or programs like vi may be confused.
+ */
+ if ((key & (KEYC_ESCAPE|KEYC_XTERM)) == KEYC_ESCAPE)
+ return (NULL);
+
/* Otherwise, find the key in the table. */
- key &= ~(KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL);
+ key &= KEYC_MASK_KEY;
for (i = 0; i < nitems(xterm_keys_table); i++) {
entry = &xterm_keys_table[i];
if (key == entry->key)