From b080f456a71d32037a4122d8c0742bfb26898c1b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 25 Sep 2013 18:59:03 +0100 Subject: [PATCH] Do not take directories into account when completing buffer name (except if a / is found in the completion prefix) --- src/buffer_manager.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index 5f3fe1ec..77e1d66e 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -99,14 +99,23 @@ CandidateList BufferManager::complete_buffername(const String& prefix, ByteCount cursor_pos) { String real_prefix = prefix.substr(0, cursor_pos); + const bool include_dirs = contains(real_prefix, '/'); CandidateList result; CandidateList subsequence_result; for (auto& buffer : m_buffers) { String name = buffer->display_name(); - if (prefix_match(name, real_prefix)) + String match_name = name; + if (not include_dirs and buffer->flags() & Buffer::Flags::File) + { + ByteCount pos = name.find_last_of('/'); + if (pos != String::npos) + match_name = name.substr(pos); + } + + if (prefix_match(match_name, real_prefix)) result.push_back(escape(name)); - if (subsequence_match(name, real_prefix)) + if (subsequence_match(match_name, real_prefix)) subsequence_result.push_back(escape(name)); } return result.empty() ? subsequence_result : result;