From 5a77db83531644f3540fd1fbd39c66383d2b83ae Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 2 Jan 2024 17:20:42 +0100 Subject: [PATCH] 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. --- src/fish_key_reader.cpp | 11 ++++------- tests/pexpects/fkr.py | 7 +++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/fish_key_reader.cpp b/src/fish_key_reader.cpp index 6e136cbdf..a555b829c 100644 --- a/src/fish_key_reader.cpp +++ b/src/fish_key_reader.cpp @@ -80,13 +80,10 @@ static maybe_t 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(); } diff --git a/tests/pexpects/fkr.py b/tests/pexpects/fkr.py index c086202d5..d37a0fb83 100644 --- a/tests/pexpects/fkr.py +++ b/tests/pexpects/fkr.py @@ -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)