From 93d40f9143941fd5995730a58e6b9b21c2ec94ae Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 29 May 2018 15:30:00 +0200 Subject: [PATCH] [input] Only timeout if the last character was escape There really is no need to - Timeout just because the _first_ character was a control character - Timeout because of any control character other than escape The reason to timeout because the '\e' sequence can appear by itself (signifying pressing the escape key) and still make sense - e.g. vi-mode has it bound to a rather important function! But a \c can't appear by itself, so we can just block. This allows binding sequences like \cx\ce and inputting them at a leisurely pace rather than the frantic escape_timeout one. It should also improve sequences that _include_ escape somewhere else. E.g. something like a\eb ("a, then alt+b") should now time out for the "\eb" part, allowing users to bind a\e ("a, then escape") to something else. Why you'd want to do that, I have no idea. But it's more consistent, and that's nice! --- src/input.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index b9eeec667..6cde72d71 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -376,12 +376,8 @@ static bool input_mapping_is_match(const input_mapping_t &m) { assert(str.size() > 0 && "zero-length input string passed to input_mapping_is_match!"); debug(4, L"trying to match mapping %ls", escape_string(m.seq.c_str(), ESCAPE_ALL).c_str()); - bool timed_first_char = iswcntrl(str[0]); + bool timed = false; for (size_t i = 0; i < str.size(); ++i) { - // Treat all strings beginning with control codes (0x00-0x1F) as timed characters, meaning they are assumed to be - // their literal representation if not followed up with another character within the defined timeout. Obviously - // we never time out on the first character in the sequence. - bool timed = i && timed_first_char; wchar_t read = input_common_readch(timed); if (read != str[i]) { @@ -393,6 +389,10 @@ static bool input_mapping_is_match(const input_mapping_t &m) { } return false; } + + // If we just read an escape, we need to add a timeout for the next char, + // to distinguish between the actual escape key and an "alt"-modifier. + timed = (str[i] == L'\e'); } return true;