1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 12:36:11 +03:00

InputHandler: use a timer for word completion instead of calling it at each insertion

This commit is contained in:
Maxime Coste 2013-01-14 19:08:00 +01:00
parent 90eeb7b8a7
commit a1998dac7a

View File

@ -3,6 +3,7 @@
#include "context.hh" #include "context.hh"
#include "editor.hh" #include "editor.hh"
#include "register_manager.hh" #include "register_manager.hh"
#include "event_manager.hh"
#include "utf8.hh" #include "utf8.hh"
#include <unordered_map> #include <unordered_map>
@ -514,7 +515,12 @@ class Insert : public InputMode
public: public:
Insert(Context& context, InsertMode mode) Insert(Context& context, InsertMode mode)
: InputMode(context.input_handler()), : 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().first = mode;
context.last_insert().second.clear(); context.last_insert().second.clear();
@ -554,7 +560,7 @@ public:
{ {
m_completer.reset(context); m_completer.reset(context);
reset_completer = false; 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' }) else if (key == Key{ Key::Modifiers::Control, 'r' })
@ -580,6 +586,7 @@ public:
private: private:
bool m_insert_reg = false; bool m_insert_reg = false;
IncrementalInserter m_inserter; IncrementalInserter m_inserter;
Timer m_complete_timer;
WordCompleter m_completer; WordCompleter m_completer;
}; };