From 38a67e72bcd8e142824f431e04f2d9ad100cffda Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 29 Jan 2013 13:49:01 +0100 Subject: [PATCH] Do not pass a context to InputHandler methods --- src/client_manager.cc | 2 +- src/commands.cc | 4 ++-- src/input_handler.cc | 21 ++++++++------------- src/input_handler.hh | 10 +++++----- src/main.cc | 14 +++++++------- 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/client_manager.cc b/src/client_manager.cc index 4b292f68..d2c1f187 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -53,7 +53,7 @@ void ClientManager::create_client(std::unique_ptr&& ui, context->ui().set_input_callback([context, this]() { try { - context->input_handler().handle_available_inputs(*context); + context->input_handler().handle_available_inputs(); context->window().forget_timestamp(); } catch (Kakoune::runtime_error& error) diff --git a/src/commands.cc b/src/commands.cc index bd34db87..7805f67f 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -532,7 +532,7 @@ void exec_keys(const KeyList& keys, Context& context) InputHandler batch_input_handler(batch_ui); batch_input_handler.context().change_editor(context.editor()); - batch_input_handler.handle_available_inputs(batch_input_handler.context()); + batch_input_handler.handle_available_inputs(); context.change_editor(batch_input_handler.context().editor()); } @@ -618,7 +618,7 @@ void menu(const CommandParameters& params, Context& context) CommandManager::instance().execute(commands[choice], context); if (event == MenuEvent::Select and choice >= 0 and choice < select_cmds.size()) CommandManager::instance().execute(select_cmds[choice], context); - }, context); + }); } void info(const CommandParameters& params, Context& context) diff --git a/src/input_handler.cc b/src/input_handler.cc index 33e9018c..ec75d899 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -617,17 +617,15 @@ InputHandler::~InputHandler() { } -void InputHandler::insert(Context& context, InsertMode mode) +void InputHandler::insert(InsertMode mode) { - assert(&context == &m_context); m_mode_trash.emplace_back(std::move(m_mode)); m_mode.reset(new InputModes::Insert(*this, mode)); } -void InputHandler::repeat_last_insert(Context& context) +void InputHandler::repeat_last_insert() { - assert(&context == &m_context); - Context::Insertion& last_insert = context.last_insert(); + Context::Insertion& last_insert = m_context.last_insert(); if (last_insert.second.empty()) return; @@ -643,17 +641,15 @@ void InputHandler::repeat_last_insert(Context& context) } void InputHandler::prompt(const String& prompt, Completer completer, - PromptCallback callback, Context& context) + PromptCallback callback) { - assert(&context == &m_context); m_mode_trash.emplace_back(std::move(m_mode)); m_mode.reset(new InputModes::Prompt(*this, prompt, completer, callback)); } void InputHandler::menu(const memoryview& choices, - MenuCallback callback, Context& context) + MenuCallback callback) { - assert(&context == &m_context); m_mode_trash.emplace_back(std::move(m_mode)); m_mode.reset(new InputModes::Menu(*this, choices, callback)); } @@ -669,13 +665,12 @@ bool is_valid(const Key& key) return key != Key::Invalid and key.key <= 0x10FFFF; } -void InputHandler::handle_available_inputs(Context& context) +void InputHandler::handle_available_inputs() { - assert(&context == &m_context); m_mode_trash.clear(); - while (context.ui().is_key_available()) + while (m_context.ui().is_key_available()) { - Key key = context.ui().get_key(); + Key key = m_context.ui().get_key(); if (is_valid(key)) m_mode->on_key(key); m_mode_trash.clear(); diff --git a/src/input_handler.hh b/src/input_handler.hh index 6a9536c0..6b260dcb 100644 --- a/src/input_handler.hh +++ b/src/input_handler.hh @@ -39,23 +39,23 @@ public: ~InputHandler(); // switch to insert mode - void insert(Context& context, InsertMode mode); + void insert(InsertMode mode); // repeat last insert mode key sequence - void repeat_last_insert(Context& context); + void repeat_last_insert(); // enter prompt mode, callback is called on each change, // abort or validation with corresponding PromptEvent value // returns to normal mode after validation if callback does // not change the mode itself void prompt(const String& prompt, Completer completer, - PromptCallback callback, Context& context); + PromptCallback callback); // enter menu mode, callback is called on each selection change, // abort or validation with corresponding MenuEvent value // returns to normal mode after validation if callback does // not change the mode itself void menu(const memoryview& choices, - MenuCallback callback, Context& context); + MenuCallback callback); // execute callback on next keypress and returns to normal mode // if callback does not change the mode itself @@ -63,7 +63,7 @@ public: // read and process all inputs available in context // user interface - void handle_available_inputs(Context& context); + void handle_available_inputs(); Context& context() { return m_context; } private: diff --git a/src/main.cc b/src/main.cc index e0e3de3f..3beb97e2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -43,12 +43,12 @@ namespace Kakoune template void do_insert(Context& context) { - context.input_handler().insert(context, mode); + context.input_handler().insert(mode); } void do_repeat_insert(Context& context) { - context.input_handler().repeat_last_insert(context); + context.input_handler().repeat_last_insert(); } template @@ -113,7 +113,7 @@ void do_command(Context& context) [](const String& cmdline, PromptEvent event, Context& context) { if (event == PromptEvent::Validate) CommandManager::instance().execute(cmdline, context); - }, context); + }); } void do_pipe(Context& context) @@ -130,7 +130,7 @@ void do_pipe(Context& context) strings.push_back(ShellManager::instance().pipe({sel.begin(), sel.end()}, cmdline, context, {}, {})); editor.insert(strings, InsertMode::Replace); - }, context); + }); } template @@ -169,7 +169,7 @@ void do_search(Context& context) throw; } - }, context); + }); } template @@ -253,7 +253,7 @@ void do_select_regex(Context& context) [](const String& ex, PromptEvent event, Context& context) { if (event == PromptEvent::Validate and not ex.empty()) context.editor().multi_select(std::bind(select_all_matches, _1, ex)); - }, context); + }); } void do_split_regex(Context& context) @@ -262,7 +262,7 @@ void do_split_regex(Context& context) [](const String& ex, PromptEvent event, Context& context) { if (event == PromptEvent::Validate and not ex.empty()) context.editor().multi_select(std::bind(split_selection, _1, ex)); - }, context); + }); } void do_join(Context& context)