mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-25 10:32:19 +03:00
Refactor Normal input mode on_key method
This commit is contained in:
parent
6ecccf4119
commit
6e08716899
@ -145,6 +145,12 @@ private:
|
|||||||
ByteCoord m_anchor;
|
ByteCoord m_anchor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr StringView register_doc =
|
||||||
|
"Special registers:\n"
|
||||||
|
" * %: buffer name\n"
|
||||||
|
" * .: selection contents\n"
|
||||||
|
" * #: selection index\n";
|
||||||
|
|
||||||
class Normal : public InputMode
|
class Normal : public InputMode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -186,30 +192,19 @@ public:
|
|||||||
|
|
||||||
void on_key(Key key, KeepAlive keep_alive) override
|
void on_key(Key key, KeepAlive keep_alive) override
|
||||||
{
|
{
|
||||||
if (m_mouse_handler.handle_key(key, context()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (m_waiting_for_reg)
|
|
||||||
{
|
|
||||||
if (auto cp = key.codepoint())
|
|
||||||
m_params.reg = *cp;
|
|
||||||
m_waiting_for_reg = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bool do_restore_hooks = false;
|
bool do_restore_hooks = false;
|
||||||
auto restore_hooks = on_scope_end([&, this]{
|
auto restore_hooks = on_scope_end([&, this]{
|
||||||
if (do_restore_hooks)
|
if (m_hooks_disabled and do_restore_hooks)
|
||||||
{
|
{
|
||||||
context().user_hooks_disabled().unset();
|
context().user_hooks_disabled().unset();
|
||||||
m_hooks_disabled = false;
|
m_hooks_disabled = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
context().print_status({});
|
|
||||||
if (context().has_ui())
|
|
||||||
context().ui().info_hide();
|
|
||||||
|
|
||||||
auto cp = key.codepoint();
|
auto cp = key.codepoint();
|
||||||
|
|
||||||
|
if (m_mouse_handler.handle_key(key, context()))
|
||||||
|
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
|
||||||
if (cp and isdigit(*cp))
|
if (cp and isdigit(*cp))
|
||||||
{
|
{
|
||||||
int new_val = m_params.count * 10 + *cp - '0';
|
int new_val = m_params.count * 10 + *cp - '0';
|
||||||
@ -230,15 +225,22 @@ public:
|
|||||||
}
|
}
|
||||||
else if (key == '"')
|
else if (key == '"')
|
||||||
{
|
{
|
||||||
m_waiting_for_reg = true;
|
on_next_key_with_autoinfo(context(), KeymapMode::None,
|
||||||
|
[this](Key key, Context&) {
|
||||||
|
if (auto cp = key.codepoint())
|
||||||
|
m_params.reg = *cp;
|
||||||
|
}, "Enter target register", register_doc);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_single_command)
|
if (m_single_command)
|
||||||
pop_mode(keep_alive);
|
pop_mode(keep_alive);
|
||||||
|
|
||||||
if (m_hooks_disabled)
|
context().print_status({});
|
||||||
do_restore_hooks = true;
|
if (context().has_ui())
|
||||||
|
context().ui().info_hide();
|
||||||
|
|
||||||
|
do_restore_hooks = true;
|
||||||
auto it = std::lower_bound(keymap.begin(), keymap.end(), key,
|
auto it = std::lower_bound(keymap.begin(), keymap.end(), key,
|
||||||
[](const NormalCmdDesc& lhs, const Key& rhs)
|
[](const NormalCmdDesc& lhs, const Key& rhs)
|
||||||
{ return lhs.key < rhs; });
|
{ return lhs.key < rhs; });
|
||||||
@ -281,7 +283,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
NormalParams m_params = { 0, 0 };
|
NormalParams m_params = { 0, 0 };
|
||||||
bool m_hooks_disabled = false;
|
bool m_hooks_disabled = false;
|
||||||
bool m_waiting_for_reg = false;
|
|
||||||
Timer m_idle_timer;
|
Timer m_idle_timer;
|
||||||
Timer m_fs_check_timer;
|
Timer m_fs_check_timer;
|
||||||
MouseHandler m_mouse_handler;
|
MouseHandler m_mouse_handler;
|
||||||
@ -620,12 +621,6 @@ String common_prefix(ConstArrayView<String> strings)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr StringView register_doc =
|
|
||||||
"Special registers:\n"
|
|
||||||
" * %: buffer name\n"
|
|
||||||
" * .: selection contents\n"
|
|
||||||
" * #: selection index\n";
|
|
||||||
|
|
||||||
class Prompt : public InputMode
|
class Prompt : public InputMode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user