1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-27 12:16:22 +03:00

Use a struct KeyAndName rather than a std::pair

This commit is contained in:
Maxime Coste 2014-12-29 17:18:42 +00:00
parent 955d1dea66
commit d4a929b42e

View File

@ -20,8 +20,8 @@ Key canonicalize_ifn(Key key)
return key;
}
using KeyAndName = std::pair<const char*, Codepoint>;
static const KeyAndName keynamemap[] = {
struct KeyAndName { const char* name; Codepoint key; };
static constexpr KeyAndName keynamemap[] = {
{ "ret", '\r' },
{ "space", ' ' },
{ "tab", '\t' },
@ -77,9 +77,9 @@ KeyList parse_keys(StringView str)
desc = desc.substr(2_byte);
}
auto name_it = find_if(keynamemap, [&desc](const KeyAndName& item)
{ return item.first == desc; });
{ return item.name == desc; });
if (name_it != end(keynamemap))
result.push_back(canonicalize_ifn({ modifier, name_it->second }));
result.push_back(canonicalize_ifn({ modifier, name_it->key }));
else if (desc.char_length() == 1)
result.push_back(Key{ modifier, desc[0_char] });
else if (tolower(desc[0]) == 'f' and desc.length() <= 3)
@ -104,11 +104,11 @@ String key_to_str(Key key)
bool named = false;
String res;
auto it = find_if(keynamemap, [&key](const KeyAndName& item)
{ return item.second == key.key; });
{ return item.key == key.key; });
if (it != end(keynamemap))
{
named = true;
res = it->first;
res = it->name;
}
else if (key.key >= Key::F1 and key.key < Key::F12)
{