diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-03-22 22:54:29 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-03-22 22:54:29 +0000 |
| commit | 5bf92430064a5136dba51402bd852398cee7e994 (patch) | |
| tree | a146fff9cb74b25a7e00a90eaa2c4afe3d451001 /src/input_handler.cc | |
| parent | c1c17db5e9a3bc62f2023bbf355b9031837ee7f4 (diff) | |
User mappings and :exec are always executed in normal mode
Fix #551
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index 0dbd5ddc..874601c2 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1325,6 +1325,35 @@ void InputHandler::on_next_key(KeymapMode keymap_mode, KeyCallback callback) push_mode(new InputModes::NextKey(*this, keymap_mode, callback)); } +InputHandler::ScopedForceNormal::ScopedForceNormal(InputHandler& handler) + : m_handler(handler), m_mode(nullptr) +{ + if (handler.m_mode_stack.size() == 1) + return; + + handler.push_mode(new InputModes::Normal(handler)); + m_mode = handler.m_mode_stack.back().get(); +} + +InputHandler::ScopedForceNormal::~ScopedForceNormal() +{ + if (not m_mode) + return; + + kak_assert(m_handler.m_mode_stack.size() > 1); + + if (m_mode == m_handler.m_mode_stack.back().get()) + m_handler.pop_mode(m_mode); + else + { + auto it = find_if(m_handler.m_mode_stack, + [this](const RefPtr<InputMode>& m) + { return m.get() == m_mode; }); + kak_assert(it != m_handler.m_mode_stack.end()); + m_handler.m_mode_stack.erase(it); + } +} + static bool is_valid(Key key) { return key != Key::Invalid and |
