From 562ee6143a2c6c1e4a282459a275a42aafb627c6 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 13 Apr 2020 12:44:15 +1000 Subject: [PATCH] Parse ascii newline/tab/escape as special keys instead of control keys Fixes #3439 --- src/keys.cc | 14 +++++++++++++- .../3439-parse-ascii-newline-as-return/cmd | 1 + .../3439-parse-ascii-newline-as-return/in | 1 + .../3439-parse-ascii-newline-as-return/out | 4 ++++ .../3439-parse-ascii-newline-as-return/rc | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/regression/3439-parse-ascii-newline-as-return/cmd create mode 100644 test/regression/3439-parse-ascii-newline-as-return/in create mode 100644 test/regression/3439-parse-ascii-newline-as-return/out create mode 100644 test/regression/3439-parse-ascii-newline-as-return/rc diff --git a/src/keys.cc b/src/keys.cc index 6343bd19..04932832 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -89,7 +89,18 @@ KeyList parse_keys(StringView str) { if (*it != '<') { - result.emplace_back(Key::Modifiers::None, *it); + auto convert = [](Codepoint cp) -> Codepoint { + switch (cp) + { + case '\n': return Key::Return; + case '\r': return Key::Return; + case '\b': return Key::Backspace; + case '\t': return Key::Tab; + case '\033': return Key::Escape; + default: return cp; + } + }; + result.emplace_back(Key::Modifiers::None, convert(*it)); continue; } @@ -219,6 +230,7 @@ UnitTest test_keys{[]() kak_assert(parse_keys("X") == KeyList{ {'X'} }); kak_assert(parse_keys("") == KeyList{ shift({Key::Up}) }); kak_assert(parse_keys("") == KeyList{ shift({Key::Tab}) }); + kak_assert(parse_keys("\n") == KeyList{ Key::Return }); kak_assert(key_to_str(shift({Key::Tab})) == ""); diff --git a/test/regression/3439-parse-ascii-newline-as-return/cmd b/test/regression/3439-parse-ascii-newline-as-return/cmd new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/regression/3439-parse-ascii-newline-as-return/cmd @@ -0,0 +1 @@ + diff --git a/test/regression/3439-parse-ascii-newline-as-return/in b/test/regression/3439-parse-ascii-newline-as-return/in new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/regression/3439-parse-ascii-newline-as-return/in @@ -0,0 +1 @@ + diff --git a/test/regression/3439-parse-ascii-newline-as-return/out b/test/regression/3439-parse-ascii-newline-as-return/out new file mode 100644 index 00000000..e6a909b7 --- /dev/null +++ b/test/regression/3439-parse-ascii-newline-as-return/out @@ -0,0 +1,4 @@ +1 + 2 + 3 + diff --git a/test/regression/3439-parse-ascii-newline-as-return/rc b/test/regression/3439-parse-ascii-newline-as-return/rc new file mode 100644 index 00000000..2395d695 --- /dev/null +++ b/test/regression/3439-parse-ascii-newline-as-return/rc @@ -0,0 +1 @@ +exec O %sh{ printf '1\n 2\n 3' }