fish_key_reader: Only name keys if they match the entire sequence

This would misname `\e\x7F` as "backspace":

bind -k backspace 'do something'
bind \e\x7F 'do something'

because it would check if there was any key *in there*.

This was probably meant for continuous mode, but it simply doesn't
work right. It's preferable to not give a key when one would work over
giving one when it's not correct.
This commit is contained in:
Fabian Boehm 2024-01-02 17:20:42 +01:00
parent 744fa72d9c
commit 5a77db8353
2 changed files with 11 additions and 7 deletions

View file

@ -80,13 +80,10 @@ static maybe_t<wcstring> sequence_name(wchar_t wc) {
recent_chars.erase(recent_chars.begin());
}
// Check all nonempty substrings extending to the end.
for (size_t i = 0; i < recent_chars.size(); i++) {
wcstring out_name;
wcstring seq = str2wcstring(recent_chars.substr(i));
if (input_terminfo_get_name(seq, out_name)) {
return out_name;
}
// The entire sequence needs to match the sequence, or else we would output substrings.
wcstring out_name;
if (input_terminfo_get_name(str2wcstring(recent_chars), out_name)) {
return out_name;
}
return none();
}

View file

@ -38,6 +38,13 @@ sleep(0.020)
send("\x00")
expect_str("char: \\c@\r\nbind -k nul 'do something'\r\n")
# Ensure we only name the sequence if we match all of it.
# Otherwise we end up calling escape+backspace "backspace"!
send("\x1b\x7f")
expect_str('char: \\e\r\n')
expect_str('char: \\x7F')
expect_str('''(aka "del")\r\nbind \\e\\x7F 'do something'\r\n''')
# Does it keep running if handed control sequences in the wrong order?
send("\x03")
sleep(0.010)