summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-10-03 20:02:37 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-10-03 20:02:37 +0100
commit9e12ac327bd46a90ef5e515247e933fed53da64f (patch)
treeeb9e7a0217193dc77b04c6e8dfe9b80659c80ac5 /src/input_handler.cc
parenta51d5a10469bc5a555c58745f1f61880990ea4f7 (diff)
Refactor hook disabling in normal mode
Normal mode takes care of keeping hooks disabled until nested modes finishes. Requiered form #818, not sufficient yet.
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 28921066..462408f7 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -154,17 +154,27 @@ public:
void on_enabled() override
{
+ m_enabled = true;
+
if (context().has_client())
context().client().check_if_buffer_needs_reloading();
m_fs_check_timer.set_next_date(Clock::now() + get_fs_check_timeout(context()));
m_idle_timer.set_next_date(Clock::now() + get_idle_timeout(context()));
+ if (m_hooks_disabled and not m_in_on_key)
+ {
+ context().hooks_disabled().unset();
+ m_hooks_disabled = false;
+ }
+
context().hooks().run_hook("NormalBegin", "", context());
}
void on_disabled() override
{
+ m_enabled = false;
+
m_idle_timer.set_next_date(TimePoint::max());
m_fs_check_timer.set_next_date(TimePoint::max());
@@ -173,9 +183,12 @@ public:
void on_key(Key key) override
{
+ m_in_on_key = true;
+ auto unset_in_on_key = on_scope_end([this]{ m_in_on_key = false; });
+
bool do_restore_hooks = false;
auto restore_hooks = on_scope_end([&, this]{
- if (m_hooks_disabled and do_restore_hooks)
+ if (m_hooks_disabled and m_enabled and do_restore_hooks)
{
context().hooks_disabled().unset();
m_hooks_disabled = false;
@@ -272,6 +285,8 @@ public:
private:
NormalParams m_params = { 0, 0 };
bool m_hooks_disabled = false;
+ bool m_enabled = false;
+ bool m_in_on_key = false;
Timer m_idle_timer;
Timer m_fs_check_timer;
MouseHandler m_mouse_handler;
@@ -939,16 +954,11 @@ public:
if (m_autoshowcompl)
m_completer.update();
context().hooks().run_hook("InsertIdle", "", context());
- }},
- m_disable_hooks{context().hooks_disabled()}
+ }}
{
- // Prolongate hook disabling for the whole insert session
- if (m_disable_hooks)
- context().hooks_disabled().set();
-
last_insert().mode = mode;
last_insert().keys.clear();
- last_insert().disable_hooks = m_disable_hooks;
+ last_insert().disable_hooks = context().hooks_disabled();
context().hooks().run_hook("InsertBegin", "", context());
prepare(m_insert_mode);
}
@@ -962,9 +972,6 @@ public:
sel.cursor() = context().buffer().char_prev(sel.cursor());
}
selections.avoid_eol();
-
- if (m_disable_hooks)
- context().hooks_disabled().unset();
}
void on_enabled() override
@@ -1237,7 +1244,6 @@ private:
InsertCompleter m_completer;
bool m_autoshowcompl;
Timer m_idle_timer;
- bool m_disable_hooks;
bool m_in_end = false;
};