summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-02-09 20:04:23 +0000
committerMaxime Coste <frrrwww@gmail.com>2016-02-09 20:04:23 +0000
commitc8dedf458dc319317cd9ff27b4c9cf82b2c342f0 (patch)
treecd0b48ba175cc43c98b0e917056f79b0ca9bfb86 /src
parent3d24badc1a60157aa13b42f6e3ffec06943b5d84 (diff)
Use the ranked word completion logic for buffer name completion
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/commands.cc b/src/commands.cc
index 3705d77b..fc318522 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -17,6 +17,7 @@
#include "option_manager.hh"
#include "option_types.hh"
#include "parameters_parser.hh"
+#include "ranked_match.hh"
#include "register_manager.hh"
#include "remote.hh"
#include "shell_manager.hh"
@@ -60,24 +61,17 @@ const PerArgumentCommandCompleter filename_completer({
static CandidateList complete_buffer_name(StringView prefix, ByteCount cursor_pos)
{
prefix = prefix.substr(0, cursor_pos);
- const bool include_dirs = contains(prefix, '/');
- CandidateList prefix_result, subsequence_result;
+ Vector<RankedMatch> matches;
for (auto& buffer : BufferManager::instance())
{
- String name = buffer->display_name();
- StringView match_name = name;
- if (not include_dirs and buffer->flags() & Buffer::Flags::File)
- {
- auto it = find(reversed(name), '/');
- if (it != name.rend())
- match_name = StringView{it.base() + 2, name.end()};
- }
- if (prefix_match(match_name, prefix))
- prefix_result.push_back(name);
- if (subsequence_match(name, prefix))
- subsequence_result.push_back(name);
+ if (RankedMatch match{buffer->display_name(), prefix})
+ matches.push_back(match);
}
- return prefix_result.empty() ? subsequence_result : prefix_result;
+ std::sort(matches.begin(), matches.end());
+ CandidateList res;
+ for (auto& m : matches)
+ res.push_back(m.candidate().str());
+ return res;
}
const PerArgumentCommandCompleter buffer_completer({