diff --git a/README.asciidoc b/README.asciidoc index abcfdfcb..f45d4c25 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -1383,6 +1383,10 @@ existing hooks are: the filtering text is the client name. * `FocusOut`: On supported clients, triggered when the client gets unfocused. the filtering text is the client name. + * `InsertCompletionShow`: Triggered when the insert completion menu gets + displayed. + * `InsertCompletionHide`: Triggered when the insert completion menu gets + hidden. When not specified, the filtering text is an empty string. diff --git a/doc/manpages/hooks.asciidoc b/doc/manpages/hooks.asciidoc index 0707d2d2..96dbc9f1 100644 --- a/doc/manpages/hooks.asciidoc +++ b/doc/manpages/hooks.asciidoc @@ -143,4 +143,10 @@ Default hooks on supported clients, triggered when the client gets unfocused. the filtering text is the client name +*InsertCompletionShow*:: + Triggered when the insert completion menu gets displayed. + +*InsertCompletionHide*:: + Triggered when the insert completion menu gets hidden. + When not specified, the filtering text is an empty string. diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 23731337..1cad959d 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -346,7 +346,7 @@ InsertCompletion complete_line(const SelectionList& sels, const OptionManager& o } -InsertCompleter::InsertCompleter(const Context& context) +InsertCompleter::InsertCompleter(Context& context) : m_context(context), m_options(context.options()) { m_options.register_watcher(*this); @@ -382,7 +382,7 @@ void InsertCompleter::select(int offset, Vector& keystrokes) { buffer.replace((pos - prefix_len).coord(), (pos + suffix_len).coord(), candidate.completion); - const_cast(selections).update(); + selections.update(); } } m_completions.end = cursor_pos; @@ -423,6 +423,7 @@ void InsertCompleter::reset() { m_context.client().menu_hide(); m_context.client().info_hide(); + m_context.hooks().run_hook("InsertCompletionHide", "", m_context); } } @@ -468,6 +469,7 @@ void InsertCompleter::menu_show() m_context.client().menu_show(std::move(menu_entries), m_completions.begin, MenuStyle::Inline); m_context.client().menu_select(m_current_candidate); + m_context.hooks().run_hook("InsertCompletionShow", "", m_context); } void InsertCompleter::on_option_changed(const Option& opt) diff --git a/src/insert_completer.hh b/src/insert_completer.hh index 8868337b..d29af8bd 100644 --- a/src/insert_completer.hh +++ b/src/insert_completer.hh @@ -75,7 +75,7 @@ struct InsertCompletion class InsertCompleter : public OptionManagerWatcher { public: - InsertCompleter(const Context& context); + InsertCompleter(Context& context); InsertCompleter(const InsertCompleter&) = delete; InsertCompleter& operator=(const InsertCompleter&) = delete; ~InsertCompleter(); @@ -97,7 +97,7 @@ private: void menu_show(); - const Context& m_context; + Context& m_context; OptionManager& m_options; InsertCompletion m_completions; int m_current_candidate = -1;