Introduce InputModeChange hook
InputModeChange <old mode>:<new mode> is intended to replace the various <Mode>Begin/<Mode>End hooks. Fixes #1772
This commit is contained in:
parent
fe49410537
commit
e0b28fa421
|
@ -120,6 +120,9 @@ of the given *group*.
|
||||||
*RuntimeError* `error message`::
|
*RuntimeError* `error message`::
|
||||||
an error was encountered while executing a user command
|
an error was encountered while executing a user command
|
||||||
|
|
||||||
|
*InputModeChange* `<old mode>:<new mode>`::
|
||||||
|
Triggered whenever the current input mode changes
|
||||||
|
|
||||||
*KakBegin*::
|
*KakBegin*::
|
||||||
kakoune has started, this hook is called just after reading the user
|
kakoune has started, this hook is called just after reading the user
|
||||||
configuration files
|
configuration files
|
||||||
|
|
|
@ -756,7 +756,7 @@ static constexpr auto hooks = {
|
||||||
"InsertBegin", "InsertChar", "InsertDelete", "InsertEnd", "InsertIdle", "InsertKey",
|
"InsertBegin", "InsertChar", "InsertDelete", "InsertEnd", "InsertIdle", "InsertKey",
|
||||||
"InsertMove", "InsertCompletionHide", "InsertCompletionShow", "InsertCompletionSelect",
|
"InsertMove", "InsertCompletionHide", "InsertCompletionShow", "InsertCompletionSelect",
|
||||||
"KakBegin", "KakEnd", "FocusIn", "FocusOut", "RuntimeError", "PromptIdle",
|
"KakBegin", "KakEnd", "FocusIn", "FocusOut", "RuntimeError", "PromptIdle",
|
||||||
"NormalBegin", "NormalEnd", "NormalIdle", "NormalKey", "RawKey",
|
"NormalBegin", "NormalEnd", "NormalIdle", "NormalKey", "InputModeChange", "RawKey",
|
||||||
"WinClose", "WinCreate", "WinDisplay", "WinResize", "WinSetOption",
|
"WinClose", "WinCreate", "WinDisplay", "WinResize", "WinSetOption",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ public:
|
||||||
|
|
||||||
virtual KeymapMode keymap_mode() const = 0;
|
virtual KeymapMode keymap_mode() const = 0;
|
||||||
|
|
||||||
|
virtual StringView name() const = 0;
|
||||||
|
|
||||||
virtual std::pair<CursorMode, DisplayCoord> get_cursor_info() const
|
virtual std::pair<CursorMode, DisplayCoord> get_cursor_info() const
|
||||||
{
|
{
|
||||||
const auto cursor = context().selections().main().cursor();
|
const auto cursor = context().selections().main().cursor();
|
||||||
|
@ -332,6 +334,8 @@ public:
|
||||||
|
|
||||||
KeymapMode keymap_mode() const override { return KeymapMode::Normal; }
|
KeymapMode keymap_mode() const override { return KeymapMode::Normal; }
|
||||||
|
|
||||||
|
StringView name() const override { return "normal"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend struct InputHandler::ScopedForceNormal;
|
friend struct InputHandler::ScopedForceNormal;
|
||||||
|
|
||||||
|
@ -652,6 +656,8 @@ public:
|
||||||
|
|
||||||
KeymapMode keymap_mode() const override { return KeymapMode::Menu; }
|
KeymapMode keymap_mode() const override { return KeymapMode::Menu; }
|
||||||
|
|
||||||
|
StringView name() const override { return "menu"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MenuCallback m_callback;
|
MenuCallback m_callback;
|
||||||
|
|
||||||
|
@ -893,6 +899,8 @@ public:
|
||||||
|
|
||||||
KeymapMode keymap_mode() const override { return KeymapMode::Prompt; }
|
KeymapMode keymap_mode() const override { return KeymapMode::Prompt; }
|
||||||
|
|
||||||
|
StringView name() const override { return "prompt"; }
|
||||||
|
|
||||||
std::pair<CursorMode, DisplayCoord> get_cursor_info() const override
|
std::pair<CursorMode, DisplayCoord> get_cursor_info() const override
|
||||||
{
|
{
|
||||||
DisplayCoord coord{0_line, m_prompt.column_length() + m_line_editor.cursor_display_column()};
|
DisplayCoord coord{0_line, m_prompt.column_length() + m_line_editor.cursor_display_column()};
|
||||||
|
@ -1026,6 +1034,8 @@ public:
|
||||||
|
|
||||||
KeymapMode keymap_mode() const override { return m_keymap_mode; }
|
KeymapMode keymap_mode() const override { return m_keymap_mode; }
|
||||||
|
|
||||||
|
StringView name() const override { return "next-key"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KeyCallback m_callback;
|
KeyCallback m_callback;
|
||||||
KeymapMode m_keymap_mode;
|
KeymapMode m_keymap_mode;
|
||||||
|
@ -1266,6 +1276,8 @@ public:
|
||||||
|
|
||||||
KeymapMode keymap_mode() const override { return KeymapMode::Insert; }
|
KeymapMode keymap_mode() const override { return KeymapMode::Insert; }
|
||||||
|
|
||||||
|
StringView name() const override { return "insert"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
void move(Type offset)
|
void move(Type offset)
|
||||||
|
@ -1395,9 +1407,13 @@ InputHandler::~InputHandler() = default;
|
||||||
|
|
||||||
void InputHandler::push_mode(InputMode* new_mode)
|
void InputHandler::push_mode(InputMode* new_mode)
|
||||||
{
|
{
|
||||||
|
StringView prev_name = current_mode().name();
|
||||||
|
|
||||||
current_mode().on_disabled(true);
|
current_mode().on_disabled(true);
|
||||||
m_mode_stack.emplace_back(new_mode);
|
m_mode_stack.emplace_back(new_mode);
|
||||||
new_mode->on_enabled();
|
new_mode->on_enabled();
|
||||||
|
|
||||||
|
context().hooks().run_hook("InputModeChange", format("{}:{}", prev_name, new_mode->name()), context());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::pop_mode(InputMode* mode)
|
void InputHandler::pop_mode(InputMode* mode)
|
||||||
|
@ -1405,20 +1421,27 @@ void InputHandler::pop_mode(InputMode* mode)
|
||||||
kak_assert(m_mode_stack.back().get() == mode);
|
kak_assert(m_mode_stack.back().get() == mode);
|
||||||
kak_assert(m_mode_stack.size() > 1);
|
kak_assert(m_mode_stack.size() > 1);
|
||||||
|
|
||||||
|
StringView prev_name = mode->name();
|
||||||
|
|
||||||
current_mode().on_disabled(false);
|
current_mode().on_disabled(false);
|
||||||
m_mode_stack.pop_back();
|
m_mode_stack.pop_back();
|
||||||
current_mode().on_enabled();
|
current_mode().on_enabled();
|
||||||
|
|
||||||
|
context().hooks().run_hook("InputModeChange", format("{}:{}", prev_name, current_mode().name()), context());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::reset_normal_mode()
|
void InputHandler::reset_normal_mode()
|
||||||
{
|
{
|
||||||
if (m_mode_stack.size() > 1)
|
kak_assert(dynamic_cast<InputModes::Normal*>(m_mode_stack[0].get()) != nullptr);
|
||||||
{
|
if (m_mode_stack.size() == 1)
|
||||||
current_mode().on_disabled(false);
|
return;
|
||||||
m_mode_stack.resize(1);
|
|
||||||
}
|
StringView prev_name = current_mode().name();
|
||||||
kak_assert(dynamic_cast<InputModes::Normal*>(¤t_mode()) != nullptr);
|
current_mode().on_disabled(false);
|
||||||
|
m_mode_stack.resize(1);
|
||||||
current_mode().on_enabled();
|
current_mode().on_enabled();
|
||||||
|
|
||||||
|
context().hooks().run_hook("InputModeChange", format("{}:{}", prev_name, current_mode().name()), context());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::insert(InsertMode mode, int count)
|
void InputHandler::insert(InsertMode mode, int count)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user