diff --git a/src/client_manager.cc b/src/client_manager.cc index 6c3b49ced..3242f0a2a 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -69,7 +69,8 @@ Client* ClientManager::create_client(std::unique_ptr&& ui, client->m_user_interface->set_input_callback([client, this]() { try { - client->m_input_handler.handle_available_inputs(); + while (client->m_user_interface->is_key_available()) + client->m_input_handler.handle_key(client->m_user_interface->get_key()); client->context().window().forget_timestamp(); } catch (Kakoune::runtime_error& error) diff --git a/src/commands.cc b/src/commands.cc index 988550c47..1dc7ba1cb 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -549,10 +549,12 @@ void context_wrap(CommandParameters params, Context& context, Func func) if (parser.has_option("draft")) { + InputHandler input_handler(real_context.ui()); Editor& editor = real_context.editor(); + input_handler.context().change_editor(editor); DynamicSelectionList sels{editor.buffer(), editor.selections()}; - auto restore_sels = on_scope_end([&]{ editor.select(sels); real_context.change_editor(editor); }); - func(parser, real_context); + auto restore_sels = on_scope_end([&]{ editor.select(sels); }); + func(parser, input_handler.context()); } else func(parser, real_context); @@ -827,38 +829,6 @@ private: char m_name; }; -class BatchUI : public UserInterface -{ -public: - BatchUI(const KeyList& keys) - : m_keys(keys), m_pos(0) {} - - Key get_key() override - { - kak_assert(m_pos < m_keys.size()); - return m_keys[m_pos++]; - } - bool is_key_available() override { return m_pos < m_keys.size(); } - - void print_status(const DisplayLine&) override {} - void draw(const DisplayBuffer&, const DisplayLine&) override {} - void menu_show(memoryview, - DisplayCoord, ColorPair, ColorPair, MenuStyle) override {} - void menu_select(int) override {} - void menu_hide() override {} - - void info_show(const String&, DisplayCoord, ColorPair, MenuStyle) override {} - void info_hide() override {} - - DisplayCoord dimensions() override { return { 0, 0 }; } - - void set_input_callback(InputCallback callback) {} - -private: - const KeyList& m_keys; - size_t m_pos; -}; - } void exec_keys(const KeyList& keys, Context& context) @@ -868,21 +838,10 @@ void exec_keys(const KeyList& keys, Context& context) scoped_edition edition(context.editor()); - BatchUI batch_ui(keys); - InputHandler batch_input_handler(batch_ui); - batch_input_handler.context().change_editor(context.editor()); - - batch_input_handler.handle_available_inputs(); - - auto& new_editor = batch_input_handler.context().editor(); - if (&new_editor != &context.editor()) - { - context.push_jump(); - context.change_editor(new_editor); - } + for (auto& key : keys) + context.input_handler().handle_key(key); } - void register_commands() { CommandManager& cm = CommandManager::instance(); diff --git a/src/input_handler.cc b/src/input_handler.cc index 72b68aa07..cd0484825 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -978,24 +978,19 @@ bool is_valid(Key key) return key != Key::Invalid and key.key <= 0x10FFFF; } -void InputHandler::handle_available_inputs() +void InputHandler::handle_key(Key key) { - m_mode_trash.clear(); - while (m_context.ui().is_key_available()) + if (is_valid(key)) { - Key key = m_context.ui().get_key(); - if (is_valid(key)) - { - const bool was_recording = is_recording(); + const bool was_recording = is_recording(); - m_mode->on_key(key); + m_mode->on_key(key); - // do not record the key that made us enter or leave recording mode. - if (was_recording and is_recording()) - m_recorded_keys += key_to_str(key); - } - m_mode_trash.clear(); + // do not record the key that made us enter or leave recording mode. + if (was_recording and is_recording()) + m_recorded_keys += key_to_str(key); } + m_mode_trash.clear(); } void InputHandler::start_recording(char reg) diff --git a/src/input_handler.hh b/src/input_handler.hh index edc9e5e0b..4089ac823 100644 --- a/src/input_handler.hh +++ b/src/input_handler.hh @@ -64,9 +64,8 @@ public: // if callback does not change the mode itself void on_next_key(KeyCallback callback); - // read and process all inputs available in context - // user interface - void handle_available_inputs(); + // process the given key + void handle_key(Key key); void start_recording(char reg); bool is_recording() const;