summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2020-12-01 20:00:38 +1100
committerMaxime Coste <mawww@kakoune.org>2020-12-01 20:00:38 +1100
commit586f79c30de2185a18f5f769e625184dd10fa40f (patch)
treec819a3deba1c870f908b71a987f8f9e55ecf54d2 /src/input_handler.cc
parent14f7d2637c80258d80e5ae204e16dbb67a896ebc (diff)
Ensure InputModes are kept alive during their idle logic
Various paths can run arbitrary commands (callbacks, hooks) which could lead to the InputMode being popped off the mode stack, but contrarily to the on_key method, we had no guarantees to be kept alive. Add a keep_alive RefPtr to this to ensure the mode survives till the end. Fixes #3915
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index ae646aaf..b7f83592 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -178,6 +178,7 @@ public:
m_idle_timer{TimePoint::max(),
context().flags() & Context::Flags::Draft ?
Timer::Callback{} : [this](Timer&) {
+ RefPtr<InputMode> keep_alive{this}; // hook could trigger pop_mode()
context().hooks().run_hook(Hook::NormalIdle, "", context());
}},
m_fs_check_timer{TimePoint::max(),
@@ -754,6 +755,7 @@ public:
m_auto_complete{context().options()["autocomplete"].get<AutoComplete>() & AutoComplete::Prompt},
m_idle_timer{TimePoint::max(), context().flags() & Context::Flags::Draft ?
Timer::Callback{} : [this](Timer&) {
+ RefPtr<InputMode> keep_alive{this}; // hook or m_callback could trigger pop_mode()
if (m_auto_complete and m_refresh_completion_pending)
refresh_completions(CompletionFlags::Fast);
if (m_line_changed)
@@ -1213,6 +1215,7 @@ public:
m_auto_complete{context().options()["autocomplete"].get<AutoComplete>() & AutoComplete::Insert},
m_idle_timer{TimePoint::max(), context().flags() & Context::Flags::Draft ?
Timer::Callback{} : [this](Timer&) {
+ RefPtr<InputMode> keep_alive{this}; // hook could trigger pop_mode()
m_completer.update(m_auto_complete);
context().hooks().run_hook(Hook::InsertIdle, "", context());
}},