diff --git a/src/client_manager.cc b/src/client_manager.cc index c4b286d5..540d18c7 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -176,7 +176,7 @@ CandidateList ClientManager::complete_client_name(StringView prefix, ByteCount cursor_pos) const { auto c = transformed(m_clients, [](const std::unique_ptr& c){ return c->context().name(); }); - return complete(prefix, cursor_pos, c, prefix_match, subsequence_match); + return complete(prefix, cursor_pos, c); } } diff --git a/src/commands.cc b/src/commands.cc index fc318522..0a34cd65 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -60,18 +60,8 @@ const PerArgumentCommandCompleter filename_completer({ static CandidateList complete_buffer_name(StringView prefix, ByteCount cursor_pos) { - prefix = prefix.substr(0, cursor_pos); - Vector matches; - for (auto& buffer : BufferManager::instance()) - { - if (RankedMatch match{buffer->display_name(), prefix}) - matches.push_back(match); - } - std::sort(matches.begin(), matches.end()); - CandidateList res; - for (auto& m : matches) - res.push_back(m.candidate().str()); - return res; + auto c = transformed(BufferManager::instance(), [](const SafePtr& b){ return b->display_name(); }); + return complete(prefix, cursor_pos, c); } const PerArgumentCommandCompleter buffer_completer({ diff --git a/src/completion.hh b/src/completion.hh index b6e53df3..47b08c73 100644 --- a/src/completion.hh +++ b/src/completion.hh @@ -2,10 +2,12 @@ #define completion_hh_INCLUDED #include +#include #include "units.hh" #include "string.hh" #include "vector.hh" +#include "ranked_match.hh" namespace Kakoune { @@ -53,41 +55,22 @@ inline Completions offset_pos(Completions completion, ByteCount offset) std::move(completion.candidates) }; } -namespace detail -{ - template - void do_matches(Container&& container, StringView prefix, - CandidateList& res, Func match_func) - { - for (auto&& elem : container) - if (match_func(elem, prefix)) - res.push_back(elem); - } - - template - void do_matches(Container&& container, StringView prefix, - CandidateList& res, Func match_func, Rest... rest) - { - do_matches(container, prefix, res, match_func); - if (res.empty()) - do_matches(container, prefix, res, rest...); - } -} - -template -CandidateList complete(StringView prefix, ByteCount cursor_pos, - const Container& container, MatchFunc... match_func) -{ - CandidateList res; - detail::do_matches(container, prefix.substr(0, cursor_pos), res, match_func...); - return res; -} - template CandidateList complete(StringView prefix, ByteCount cursor_pos, const Container& container) { - return complete(prefix, cursor_pos, container, prefix_match); + prefix = prefix.substr(0, cursor_pos); + Vector matches; + for (const auto& str : container) + { + if (RankedMatch match{str, prefix}) + matches.push_back(match); + } + std::sort(matches.begin(), matches.end()); + CandidateList res; + for (auto& m : matches) + res.push_back(m.candidate().str()); + return res; } }