From ec6ecd57725af15f557d3409114e0698a13cee6c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 25 Nov 2017 13:47:04 +0800 Subject: [PATCH] Add an InsertCompletionSelect hook InsertCompletionSelect will be called whenever the selected insert completion changes. If the original text is selected back, the hook parameter will be empty. If another candidate is selected, the hook parameter will be its text content. Fixes #1676 --- doc/pages/hooks.asciidoc | 5 +++++ src/commands.cc | 2 +- src/insert_completer.cc | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) 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()