diff --git a/src/input_handler.cc b/src/input_handler.cc index d4214ed1..25ceacc3 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -281,19 +281,18 @@ public: context().client().info_hide(); do_restore_hooks = true; - auto it = keymap.find(key); - if (it != keymap.end() and it->key == key) + if (auto command = get_normal_command(key)) { auto autoinfo = context().options()["autoinfo"].get(); if (autoinfo & AutoInfo::Normal and context().has_client()) - context().client().info_show(key_to_str(key), it->value.docstring.str(), + context().client().info_show(key_to_str(key), command->docstring.str(), {}, InfoStyle::Prompt); // reset m_params now to be reentrant NormalParams params = m_params; m_params = { 0, 0 }; - it->value.func(context(), params); + command->func(context(), params); } } diff --git a/src/normal.cc b/src/normal.cc index 454c8fdc..213598d3 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1943,7 +1943,7 @@ void force_redraw(Context& context, NormalParams) } } -const HashMap keymap{ +static const HashMap keymap{ { {'h'}, {"move left", move} }, { {'j'}, {"move down", move} }, { {'k'}, {"move up", move} }, @@ -2131,4 +2131,12 @@ const HashMap keymap{ { {ctrl('l')}, {"force redraw", force_redraw} }, }; +Optional get_normal_command(Key key) +{ + auto it = keymap.find(key); + if (it != keymap.end()) + return it->value; + return {}; +} + } diff --git a/src/normal.hh b/src/normal.hh index bb2d3ecc..061ab029 100644 --- a/src/normal.hh +++ b/src/normal.hh @@ -1,7 +1,7 @@ #ifndef normal_hh_INCLUDED #define normal_hh_INCLUDED -#include "hash_map.hh" +#include "optional.hh" #include "keys.hh" #include "string.hh" @@ -22,7 +22,7 @@ struct NormalCmd void (*func)(Context& context, NormalParams params); }; -extern const HashMap keymap; +Optional get_normal_command(Key key); }