diff --git a/src/client_manager.cc b/src/client_manager.cc index 91cc6406..f818e226 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -166,4 +166,22 @@ void ClientManager::redraw_clients() const client->redraw_ifn(); } +CandidateList ClientManager::complete_client_name(const String& prefix, + ByteCount cursor_pos) const +{ + String real_prefix = prefix.substr(0, cursor_pos); + CandidateList result; + CandidateList subsequence_result; + for (auto& client : m_clients) + { + const String& name = client->context().name(); + + if (prefix_match(name, real_prefix)) + result.push_back(escape(name)); + if (subsequence_match(name, real_prefix)) + subsequence_result.push_back(escape(name)); + } + return result.empty() ? subsequence_result : result; +} + } diff --git a/src/client_manager.hh b/src/client_manager.hh index b20a1a69..cc5c6c0c 100644 --- a/src/client_manager.hh +++ b/src/client_manager.hh @@ -2,6 +2,7 @@ #define client_manager_hh_INCLUDED #include "client.hh" +#include "completion.hh" namespace Kakoune { @@ -38,6 +39,9 @@ public: bool validate_client_name(const String& name) const; void remove_client(Client& client); + CandidateList complete_client_name(const String& name, + ByteCount cursor_pos = -1) const; + private: String generate_name() const;