Use a struct KeyAndName rather than a std::pair
This commit is contained in:
parent
955d1dea66
commit
d4a929b42e
12
src/keys.cc
12
src/keys.cc
|
@ -20,8 +20,8 @@ Key canonicalize_ifn(Key key)
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
using KeyAndName = std::pair<const char*, Codepoint>;
|
struct KeyAndName { const char* name; Codepoint key; };
|
||||||
static const KeyAndName keynamemap[] = {
|
static constexpr KeyAndName keynamemap[] = {
|
||||||
{ "ret", '\r' },
|
{ "ret", '\r' },
|
||||||
{ "space", ' ' },
|
{ "space", ' ' },
|
||||||
{ "tab", '\t' },
|
{ "tab", '\t' },
|
||||||
|
@ -77,9 +77,9 @@ KeyList parse_keys(StringView str)
|
||||||
desc = desc.substr(2_byte);
|
desc = desc.substr(2_byte);
|
||||||
}
|
}
|
||||||
auto name_it = find_if(keynamemap, [&desc](const KeyAndName& item)
|
auto name_it = find_if(keynamemap, [&desc](const KeyAndName& item)
|
||||||
{ return item.first == desc; });
|
{ return item.name == desc; });
|
||||||
if (name_it != end(keynamemap))
|
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)
|
else if (desc.char_length() == 1)
|
||||||
result.push_back(Key{ modifier, desc[0_char] });
|
result.push_back(Key{ modifier, desc[0_char] });
|
||||||
else if (tolower(desc[0]) == 'f' and desc.length() <= 3)
|
else if (tolower(desc[0]) == 'f' and desc.length() <= 3)
|
||||||
|
@ -104,11 +104,11 @@ String key_to_str(Key key)
|
||||||
bool named = false;
|
bool named = false;
|
||||||
String res;
|
String res;
|
||||||
auto it = find_if(keynamemap, [&key](const KeyAndName& item)
|
auto it = find_if(keynamemap, [&key](const KeyAndName& item)
|
||||||
{ return item.second == key.key; });
|
{ return item.key == key.key; });
|
||||||
if (it != end(keynamemap))
|
if (it != end(keynamemap))
|
||||||
{
|
{
|
||||||
named = true;
|
named = true;
|
||||||
res = it->first;
|
res = it->name;
|
||||||
}
|
}
|
||||||
else if (key.key >= Key::F1 and key.key < Key::F12)
|
else if (key.key >= Key::F1 and key.key < Key::F12)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user