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.
This commit is contained in:
parent
209113aa1c
commit
ddff35e5ab
|
@ -281,19 +281,18 @@ public:
|
||||||
context().client().info_hide();
|
context().client().info_hide();
|
||||||
|
|
||||||
do_restore_hooks = true;
|
do_restore_hooks = true;
|
||||||
auto it = keymap.find(key);
|
if (auto command = get_normal_command(key))
|
||||||
if (it != keymap.end() and it->key == key)
|
|
||||||
{
|
{
|
||||||
auto autoinfo = context().options()["autoinfo"].get<AutoInfo>();
|
auto autoinfo = context().options()["autoinfo"].get<AutoInfo>();
|
||||||
if (autoinfo & AutoInfo::Normal and context().has_client())
|
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);
|
{}, InfoStyle::Prompt);
|
||||||
|
|
||||||
// reset m_params now to be reentrant
|
// reset m_params now to be reentrant
|
||||||
NormalParams params = m_params;
|
NormalParams params = m_params;
|
||||||
m_params = { 0, 0 };
|
m_params = { 0, 0 };
|
||||||
|
|
||||||
it->value.func(context(), params);
|
command->func(context(), params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>} },
|
{ {'h'}, {"move left", move<CharCount, Backward>} },
|
||||||
{ {'j'}, {"move down", move<LineCount, Forward>} },
|
{ {'j'}, {"move down", move<LineCount, Forward>} },
|
||||||
{ {'k'}, {"move up", move<LineCount, Backward>} },
|
{ {'k'}, {"move up", move<LineCount, Backward>} },
|
||||||
|
@ -2131,4 +2131,12 @@ const HashMap<Key, NormalCmd> keymap{
|
||||||
{ {ctrl('l')}, {"force redraw", force_redraw} },
|
{ {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 {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef normal_hh_INCLUDED
|
#ifndef normal_hh_INCLUDED
|
||||||
#define normal_hh_INCLUDED
|
#define normal_hh_INCLUDED
|
||||||
|
|
||||||
#include "hash_map.hh"
|
#include "optional.hh"
|
||||||
#include "keys.hh"
|
#include "keys.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ struct NormalCmd
|
||||||
void (*func)(Context& context, NormalParams params);
|
void (*func)(Context& context, NormalParams params);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const HashMap<Key, NormalCmd> keymap;
|
Optional<NormalCmd> get_normal_command(Key key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user