From 441f9a69efc18630b4c508688ef403b0ed81b19d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 10 Apr 2013 14:30:32 +0200 Subject: [PATCH] InputHandler: auto leave insert mode when editor changed --- src/input_handler.cc | 20 +++++++++----------- 1 file 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; }