summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-04-10 14:30:32 +0200
committerMaxime Coste <frrrwww@gmail.com>2013-04-10 14:30:32 +0200
commit441f9a69efc18630b4c508688ef403b0ed81b19d (patch)
treedb96274174dbe6bdcc698bb04948beb89f25a1e2 /src/input_handler.cc
parentbdd617006b5f6d50f58bb63442866987741addcd (diff)
InputHandler: auto leave insert mode when editor changed
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 95071bd2..e3ca427d 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -31,7 +31,7 @@ public:
Insertion& last_insert() { return m_input_handler.m_last_insert; }
protected:
- void reset_normal_mode();
+ InputMode& reset_normal_mode();
private:
InputHandler& m_input_handler;
};
@@ -553,18 +553,12 @@ static BufferCompletion complete_opt(const BufferIterator& pos, OptionManager& o
return {};
}
-class BufferCompleter : public OptionManagerWatcher
+class BufferCompleter : public OptionManagerWatcher_AutoRegister
{
public:
BufferCompleter(const Context& context)
- : m_context(context)
- {
- m_context.options().register_watcher(*this);
- }
- ~BufferCompleter()
- {
- m_context.options().unregister_watcher(*this);
- }
+ : OptionManagerWatcher_AutoRegister(context.options()), m_context(context)
+ {}
BufferCompleter(const BufferCompleter&) = delete;
BufferCompleter& operator=(const BufferCompleter&) = delete;
@@ -690,6 +684,9 @@ public:
void on_key(const Key& key) override
{
+ if (&context().editor() != &m_inserter.editor())
+ return reset_normal_mode().on_key(key);
+
last_insert().second.push_back(key);
if (m_insert_reg)
{
@@ -764,10 +761,11 @@ private:
}
-void InputMode::reset_normal_mode()
+InputMode& InputMode::reset_normal_mode()
{
m_input_handler.m_mode_trash.emplace_back(std::move(m_input_handler.m_mode));
m_input_handler.m_mode.reset(new InputModes::Normal(m_input_handler));
+ return *m_input_handler.m_mode;
}