Change multi modifier key syntax to be <c-a-space> instead of <ca-space>

Better fix for #1311
This commit is contained in:
Maxime Coste 2017-04-11 10:44:14 +01:00
parent 112bd156e4
commit 413d8b7ddd

View File

@ -77,24 +77,21 @@ KeyList parse_keys(StringView str)
Key::Modifiers modifier = Key::Modifiers::None; Key::Modifiers modifier = Key::Modifiers::None;
StringView full_desc{it.base(), end_it.base()+1};
StringView desc{it.base()+1, end_it.base()}; StringView desc{it.base()+1, end_it.base()};
auto dash = find(desc, '-'); for (auto dash = find(desc, '-'); dash != desc.end(); dash = find(desc, '-'))
if (dash != desc.end())
{ {
if (dash == desc.begin()) if (dash != desc.begin() + 1)
throw runtime_error("unable to parse modifier in " + throw runtime_error(format("unable to parse modifier in '{}'",
StringView{it.base(), end_it.base()+1}); full_desc));
for (auto c : StringView{desc.begin(), dash}) switch(to_lower(desc[0_byte]))
{ {
switch(to_lower(c)) case 'c': modifier |= Key::Modifiers::Control; break;
{ case 'a': modifier |= Key::Modifiers::Alt; break;
case 'c': modifier |= Key::Modifiers::Control; break; default:
case 'a': modifier |= Key::Modifiers::Alt; break; throw runtime_error(format("unable to parse modifier in '{}'",
default: full_desc));
throw runtime_error("unable to parse modifier in " +
StringView{it.base(), end_it.base()+1});
}
} }
desc = StringView{dash+1, desc.end()}; desc = StringView{dash+1, desc.end()};
} }
@ -169,7 +166,7 @@ String key_to_str(Key key)
{ {
case Key::Modifiers::Control: res = "c-" + res; named = true; break; case Key::Modifiers::Control: res = "c-" + res; named = true; break;
case Key::Modifiers::Alt: res = "a-" + res; named = true; break; case Key::Modifiers::Alt: res = "a-" + res; named = true; break;
case Key::Modifiers::ControlAlt: res = "ca-" + res; named = true; break; case Key::Modifiers::ControlAlt: res = "c-a-" + res; named = true; break;
default: break; default: break;
} }
if (named) if (named)
@ -190,6 +187,8 @@ UnitTest test_keys{[]()
keys_as_str += key_to_str(key); keys_as_str += key_to_str(key);
auto parsed_keys = parse_keys(keys_as_str); auto parsed_keys = parse_keys(keys_as_str);
kak_assert(keys == parsed_keys); kak_assert(keys == parsed_keys);
kak_assert(ConstArrayView<Key>{parse_keys("a<c-a-b>c")} ==
ConstArrayView<Key>{'a', {Key::Modifiers::ControlAlt, 'b'}, 'c'});
}}; }};
} }