[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!
This commit is contained in:
Fabian Homborg 2018-05-29 15:30:00 +02:00
parent 725062d360
commit 93d40f9143

View file

@ -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!"); 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()); 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) { 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); wchar_t read = input_common_readch(timed);
if (read != str[i]) { if (read != str[i]) {
@ -393,6 +389,10 @@ static bool input_mapping_is_match(const input_mapping_t &m) {
} }
return false; 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; return true;