diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-02-09 22:50:10 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-02-09 22:50:10 +0000 |
| commit | 87769c9b03b516053249f86355a4e503a529c659 (patch) | |
| tree | 80521de80ecef7c95b40297265cb7d77941e2fa6 /src | |
| parent | c0e4eca982078c21f7cf4962b5b38119a888c777 (diff) | |
Migrate most completion to ranked match
Diffstat (limited to 'src')
| -rw-r--r-- | src/client_manager.cc | 2 | ||||
| -rw-r--r-- | src/commands.cc | 14 | ||||
| -rw-r--r-- | src/completion.hh | 43 |
3 files changed, 16 insertions, 43 deletions
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<Client>& 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<RankedMatch> 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<Buffer>& 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 <functional> +#include <algorithm> #include "units.hh" #include "string.hh" #include "vector.hh" +#include "ranked_match.hh" namespace Kakoune { @@ -53,42 +55,23 @@ inline Completions offset_pos(Completions completion, ByteCount offset) std::move(completion.candidates) }; } -namespace detail +template<typename Container> +CandidateList complete(StringView prefix, ByteCount cursor_pos, + const Container& container) { - template<typename Container, typename Func> - 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<typename Container, typename Func, typename... Rest> - void do_matches(Container&& container, StringView prefix, - CandidateList& res, Func match_func, Rest... rest) + prefix = prefix.substr(0, cursor_pos); + Vector<RankedMatch> matches; + for (const auto& str : container) { - do_matches(container, prefix, res, match_func); - if (res.empty()) - do_matches(container, prefix, res, rest...); + if (RankedMatch match{str, prefix}) + matches.push_back(match); } -} - -template<typename Container, typename... MatchFunc> -CandidateList complete(StringView prefix, ByteCount cursor_pos, - const Container& container, MatchFunc... match_func) -{ + std::sort(matches.begin(), matches.end()); CandidateList res; - detail::do_matches(container, prefix.substr(0, cursor_pos), res, match_func...); + for (auto& m : matches) + res.push_back(m.candidate().str()); return res; } -template<typename Container> -CandidateList complete(StringView prefix, ByteCount cursor_pos, - const Container& container) -{ - return complete(prefix, cursor_pos, container, prefix_match); -} - } #endif // completion_hh_INCLUDED |
