diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-10-17 11:29:52 +0800 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-10-20 12:21:22 +0800 |
| commit | ddff35e5ab6a9bed29c49547eaee91637854f029 (patch) | |
| tree | b6059182aac4aa418fa9d5d7628ba67efa34839b /src | |
| parent | 209113aa1c37464687612520542795900d461215 (diff) | |
Move keymap as an implementation detail of the normal mode keys
Only expose a free function that tries to get the NormalCmd from a
key.
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_handler.cc | 7 | ||||
| -rw-r--r-- | src/normal.cc | 10 | ||||
| -rw-r--r-- | src/normal.hh | 4 |
3 files changed, 14 insertions, 7 deletions
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<AutoInfo>(); 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<Key, NormalCmd> keymap{ +static const HashMap<Key, NormalCmd> keymap{ { {'h'}, {"move left", move<CharCount, Backward>} }, { {'j'}, {"move down", move<LineCount, Forward>} }, { {'k'}, {"move up", move<LineCount, Backward>} }, @@ -2131,4 +2131,12 @@ const HashMap<Key, NormalCmd> keymap{ { {ctrl('l')}, {"force redraw", force_redraw} }, }; +Optional<NormalCmd> 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<Key, NormalCmd> keymap; +Optional<NormalCmd> get_normal_command(Key key); } |
