diff --git a/doc/pages/hooks.asciidoc b/doc/pages/hooks.asciidoc index 6dd455f2..304bf5fa 100644 --- a/doc/pages/hooks.asciidoc +++ b/doc/pages/hooks.asciidoc @@ -151,6 +151,11 @@ of the given *group*. *InsertCompletionHide*:: Triggered when the insert completion menu gets hidden +*InsertCompletionSelect*:: + Triggered when an entry is selected in the insert completion + menu. The filtering text is the selected completion text or + the empty string if the original text was selected back. + *RawKey*:: Triggered whenever a key is pressed by the user, the key is used for filtering. diff --git a/src/commands.cc b/src/commands.cc index 1a8e8f73..8ae74c7c 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -752,7 +752,7 @@ static constexpr auto hooks = { "BufCreate", "BufNewFile", "BufOpenFile", "BufClose", "BufWritePost", "BufWritePre", "BufOpenFifo", "BufCloseFifo", "BufReadFifo", "BufSetOption", "InsertBegin", "InsertChar", "InsertDelete", "InsertEnd", "InsertIdle", "InsertKey", - "InsertMove", "InsertCompletionHide", "InsertCompletionShow", + "InsertMove", "InsertCompletionHide", "InsertCompletionShow", "InsertCompletionSelect", "KakBegin", "KakEnd", "FocusIn", "FocusOut", "RuntimeError", "PromptIdle", "NormalBegin", "NormalEnd", "NormalIdle", "NormalKey", "RawKey", "WinClose", "WinCreate", "WinDisplay", "WinResize", "WinSetOption", diff --git a/src/insert_completer.cc b/src/insert_completer.cc index d8730f70..4a4e9be0 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -425,6 +425,13 @@ void InsertCompleter::select(int offset, Vector& keystrokes) keystrokes.emplace_back(Key::Delete); for (auto& c : candidate.completion) keystrokes.emplace_back(c); + + if (m_context.has_client()) + { + const auto param = (m_current_candidate == m_completions.candidates.size() - 1) ? + StringView{} : candidate.completion; + m_context.hooks().run_hook("InsertCompletionSelect", param, m_context); + } } void InsertCompleter::update()