From 8e92e0eebcf38d539fe055e455b8d628f5caf9f3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 5 Jan 2015 19:33:33 +0000 Subject: [PATCH] Go back to previous buffer name completion implementation --- src/commands.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index c4bc5d624..192c93fd9 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -56,19 +56,25 @@ const PerArgumentCommandCompleter filename_completer({ static CandidateList complete_buffer_name(StringView prefix, ByteCount cursor_pos) { - const bool include_dirs = contains(prefix.substr(0, cursor_pos), '/'); - auto c = transformed(BufferManager::instance(), - [include_dirs](const safe_ptr& buffer) -> String { + prefix = prefix.substr(0, cursor_pos); + const bool include_dirs = contains(prefix, '/'); + CandidateList prefix_result, subsequence_result; + for (auto& buffer : BufferManager::instance()) + { String name = buffer->display_name(); + StringView match_name = name; if (not include_dirs and buffer->flags() & Buffer::Flags::File) { ByteCount pos = name.find_last_of('/'); if (pos != (int)String::npos) - return name.substr(pos+1); + match_name = name.substr(pos+1); } - return name; - }); - return complete(prefix, cursor_pos, c, prefix_match, subsequence_match); + if (prefix_match(match_name, prefix)) + prefix_result.push_back(name); + if (subsequence_match(name, prefix)) + subsequence_result.push_back(name); + } + return prefix_result.empty() ? subsequence_result : prefix_result; } const PerArgumentCommandCompleter buffer_completer({