Add ClientManager::complete_client_name

This commit is contained in:
Maxime Coste 2014-04-07 21:43:55 +01:00
parent a9b3a8b0d6
commit ca54909246
2 changed files with 22 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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;