summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-11-09 21:30:07 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-11-09 21:30:07 +0000
commit6e08716899cbf144d46f97d29fe7e449da06a738 (patch)
treef4319aae776b0869731f1c771b367371a898b180 /src/input_handler.cc
parent6ecccf4119bdc029b6ef9d78a5b131100a1d7af3 (diff)
Refactor Normal input mode on_key method
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc45
1 files changed, 20 insertions, 25 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 1b98fb19..6b35fcc5 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -145,6 +145,12 @@ private:
ByteCoord m_anchor;
};
+constexpr StringView register_doc =
+ "Special registers:\n"
+ " * %: buffer name\n"
+ " * .: selection contents\n"
+ " * #: selection index\n";
+
class Normal : public InputMode
{
public:
@@ -186,30 +192,19 @@ public:
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;
auto restore_hooks = on_scope_end([&, this]{
- if (do_restore_hooks)
+ if (m_hooks_disabled and do_restore_hooks)
{
context().user_hooks_disabled().unset();
m_hooks_disabled = false;
}
});
- context().print_status({});
- if (context().has_ui())
- context().ui().info_hide();
-
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))
{
int new_val = m_params.count * 10 + *cp - '0';
@@ -230,15 +225,22 @@ public:
}
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
{
if (m_single_command)
pop_mode(keep_alive);
- if (m_hooks_disabled)
- do_restore_hooks = true;
+ context().print_status({});
+ if (context().has_ui())
+ context().ui().info_hide();
+
+ do_restore_hooks = true;
auto it = std::lower_bound(keymap.begin(), keymap.end(), key,
[](const NormalCmdDesc& lhs, const Key& rhs)
{ return lhs.key < rhs; });
@@ -281,7 +283,6 @@ public:
private:
NormalParams m_params = { 0, 0 };
bool m_hooks_disabled = false;
- bool m_waiting_for_reg = false;
Timer m_idle_timer;
Timer m_fs_check_timer;
MouseHandler m_mouse_handler;
@@ -620,12 +621,6 @@ String common_prefix(ConstArrayView<String> strings)
return res;
}
-constexpr StringView register_doc =
- "Special registers:\n"
- " * %: buffer name\n"
- " * .: selection contents\n"
- " * #: selection index\n";
-
class Prompt : public InputMode
{
public: