Add InsertCompletionShow/InsertCompletionHide hooks

This commit is contained in:
Maxime Coste 2016-09-21 13:38:34 +01:00
parent 12f2815159
commit 532e3758fe
4 changed files with 16 additions and 4 deletions

View File

@ -1383,6 +1383,10 @@ existing hooks are:
the filtering text is the client name. the filtering text is the client name.
* `FocusOut`: On supported clients, triggered when the client gets unfocused. * `FocusOut`: On supported clients, triggered when the client gets unfocused.
the filtering text is the client name. 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. When not specified, the filtering text is an empty string.

View File

@ -143,4 +143,10 @@ Default hooks
on supported clients, triggered when the client gets unfocused. the on supported clients, triggered when the client gets unfocused. the
filtering text is the client name 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. When not specified, the filtering text is an empty string.

View File

@ -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_context(context), m_options(context.options())
{ {
m_options.register_watcher(*this); m_options.register_watcher(*this);
@ -382,7 +382,7 @@ void InsertCompleter::select(int offset, Vector<Key>& keystrokes)
{ {
buffer.replace((pos - prefix_len).coord(), buffer.replace((pos - prefix_len).coord(),
(pos + suffix_len).coord(), candidate.completion); (pos + suffix_len).coord(), candidate.completion);
const_cast<SelectionList&>(selections).update(); selections.update();
} }
} }
m_completions.end = cursor_pos; m_completions.end = cursor_pos;
@ -423,6 +423,7 @@ void InsertCompleter::reset()
{ {
m_context.client().menu_hide(); m_context.client().menu_hide();
m_context.client().info_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, m_context.client().menu_show(std::move(menu_entries), m_completions.begin,
MenuStyle::Inline); MenuStyle::Inline);
m_context.client().menu_select(m_current_candidate); m_context.client().menu_select(m_current_candidate);
m_context.hooks().run_hook("InsertCompletionShow", "", m_context);
} }
void InsertCompleter::on_option_changed(const Option& opt) void InsertCompleter::on_option_changed(const Option& opt)

View File

@ -75,7 +75,7 @@ struct InsertCompletion
class InsertCompleter : public OptionManagerWatcher class InsertCompleter : public OptionManagerWatcher
{ {
public: public:
InsertCompleter(const Context& context); InsertCompleter(Context& context);
InsertCompleter(const InsertCompleter&) = delete; InsertCompleter(const InsertCompleter&) = delete;
InsertCompleter& operator=(const InsertCompleter&) = delete; InsertCompleter& operator=(const InsertCompleter&) = delete;
~InsertCompleter(); ~InsertCompleter();
@ -97,7 +97,7 @@ private:
void menu_show(); void menu_show();
const Context& m_context; Context& m_context;
OptionManager& m_options; OptionManager& m_options;
InsertCompletion m_completions; InsertCompletion m_completions;
int m_current_candidate = -1; int m_current_candidate = -1;