From a1998dac7a0766202a953e137dd3ea061414a20f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 14 Jan 2013 19:08:00 +0100 Subject: [PATCH] InputHandler: use a timer for word completion instead of calling it at each insertion --- src/input_handler.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index d3cd8460d..e411110d1 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -3,6 +3,7 @@ #include "context.hh" #include "editor.hh" #include "register_manager.hh" +#include "event_manager.hh" #include "utf8.hh" #include @@ -514,7 +515,12 @@ class Insert : public InputMode public: Insert(Context& context, InsertMode mode) : InputMode(context.input_handler()), - m_inserter(context.editor(), mode) + m_inserter(context.editor(), mode), + m_complete_timer{Clock::time_point::max(), + [this, &context](Timer& timer) { + m_completer.reset(context); + m_completer.select(context, 0); + }} { context.last_insert().first = mode; context.last_insert().second.clear(); @@ -554,7 +560,7 @@ public: { m_completer.reset(context); reset_completer = false; - m_completer.select(context, 0); + m_complete_timer.set_next_date(Clock::now() + std::chrono::milliseconds{250}); } } else if (key == Key{ Key::Modifiers::Control, 'r' }) @@ -580,6 +586,7 @@ public: private: bool m_insert_reg = false; IncrementalInserter m_inserter; + Timer m_complete_timer; WordCompleter m_completer; };