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]() {
|
client->m_user_interface->set_input_callback([client, this]() {
|
||||||
try
|
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();
|
client->context().window().forget_timestamp();
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& error)
|
catch (Kakoune::runtime_error& error)
|
||||||
|
|
|
@ -549,10 +549,12 @@ void context_wrap(CommandParameters params, Context& context, Func func)
|
||||||
|
|
||||||
if (parser.has_option("draft"))
|
if (parser.has_option("draft"))
|
||||||
{
|
{
|
||||||
|
InputHandler input_handler(real_context.ui());
|
||||||
Editor& editor = real_context.editor();
|
Editor& editor = real_context.editor();
|
||||||
|
input_handler.context().change_editor(editor);
|
||||||
DynamicSelectionList sels{editor.buffer(), editor.selections()};
|
DynamicSelectionList sels{editor.buffer(), editor.selections()};
|
||||||
auto restore_sels = on_scope_end([&]{ editor.select(sels); real_context.change_editor(editor); });
|
auto restore_sels = on_scope_end([&]{ editor.select(sels); });
|
||||||
func(parser, real_context);
|
func(parser, input_handler.context());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
func(parser, real_context);
|
func(parser, real_context);
|
||||||
|
@ -827,38 +829,6 @@ private:
|
||||||
char m_name;
|
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)
|
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());
|
scoped_edition edition(context.editor());
|
||||||
|
|
||||||
BatchUI batch_ui(keys);
|
for (auto& key : keys)
|
||||||
InputHandler batch_input_handler(batch_ui);
|
context.input_handler().handle_key(key);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void register_commands()
|
void register_commands()
|
||||||
{
|
{
|
||||||
CommandManager& cm = CommandManager::instance();
|
CommandManager& cm = CommandManager::instance();
|
||||||
|
|
|
@ -978,12 +978,8 @@ bool is_valid(Key key)
|
||||||
return key != Key::Invalid and key.key <= 0x10FFFF;
|
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())
|
|
||||||
{
|
|
||||||
Key key = m_context.ui().get_key();
|
|
||||||
if (is_valid(key))
|
if (is_valid(key))
|
||||||
{
|
{
|
||||||
const bool was_recording = is_recording();
|
const bool was_recording = is_recording();
|
||||||
|
@ -995,7 +991,6 @@ void InputHandler::handle_available_inputs()
|
||||||
m_recorded_keys += key_to_str(key);
|
m_recorded_keys += key_to_str(key);
|
||||||
}
|
}
|
||||||
m_mode_trash.clear();
|
m_mode_trash.clear();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::start_recording(char reg)
|
void InputHandler::start_recording(char reg)
|
||||||
|
|
|
@ -64,9 +64,8 @@ public:
|
||||||
// if callback does not change the mode itself
|
// if callback does not change the mode itself
|
||||||
void on_next_key(KeyCallback callback);
|
void on_next_key(KeyCallback callback);
|
||||||
|
|
||||||
// read and process all inputs available in context
|
// process the given key
|
||||||
// user interface
|
void handle_key(Key key);
|
||||||
void handle_available_inputs();
|
|
||||||
|
|
||||||
void start_recording(char reg);
|
void start_recording(char reg);
|
||||||
bool is_recording() const;
|
bool is_recording() const;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user