From c52548f6fd311e4df3076ba4cc6f6ab8849557ac Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 10 Feb 2014 11:20:41 +0000 Subject: [PATCH] The last fix to xterm keys meant that some keys such as \033OA were being wrongly treated as partial matches. So both check xterm keys after standard keys and only wildcard the minimum required ('1' to '8'). Problems reported by Ralf Horstmann and Tim van der Molen. --- tty-keys.c | 18 +++++++++--------- xterm-keys.c | 4 +++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tty-keys.c b/tty-keys.c index 7de5ce59..4492df1e 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -479,6 +479,15 @@ tty_keys_next(struct tty *tty) goto partial_key; } + /* Look for matching key string and return if found. */ + tk = tty_keys_find(tty, buf, len, &size); + if (tk != NULL) { + if (tk->next != NULL) + goto partial_key; + key = tk->key; + goto complete_key; + } + /* Try to parse a key with an xterm-style modifier. */ switch (xterm_keys_find(buf, len, &size, &key)) { case 0: /* found */ @@ -489,15 +498,6 @@ tty_keys_next(struct tty *tty) goto partial_key; } - /* Look for matching key string and return if found. */ - tk = tty_keys_find(tty, buf, len, &size); - if (tk != NULL) { - if (tk->next != NULL) - goto partial_key; - key = tk->key; - goto complete_key; - } - first_key: /* Is this a meta key? */ if (len >= 2 && buf[0] == '\033') { diff --git a/xterm-keys.c b/xterm-keys.c index 9b5a0a21..0e20165b 100644 --- a/xterm-keys.c +++ b/xterm-keys.c @@ -131,7 +131,9 @@ xterm_keys_match(const char *template, const char *buf, size_t len) pos = 0; do { - if (*template != '_' && buf[pos] != *template) + if (*template == '_' && buf[pos] >= '1' && buf[pos] <= '8') + continue; + if (buf[pos] != *template) return (-1); } while (*++template != '\0' && ++pos != len);