mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-24 07:53:41 +03:00
Allow :exec mode changes to remains when keys are finished
Pass keys one by one to the input handler so that BatchUI is not needed We can now use :exec to pre-fill the command line without validating the command.
This commit is contained in:
parent
96fc340a5c
commit
916a0cb52e
@ -69,7 +69,8 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& 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)
|
||||
|
@ -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<String>,
|
||||
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();
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user