diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index 943a2085b..109366f63 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -115,24 +115,6 @@ void BufferManager::backup_modified_buffers() } } -CandidateList BufferManager::complete_buffer_name(StringView prefix, - ByteCount cursor_pos) -{ - const bool include_dirs = contains(prefix.substr(0, cursor_pos), '/'); - auto c = transformed(m_buffers, - [include_dirs](const safe_ptr& buffer) -> String { - String name = buffer->display_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); - } - return name; - }); - return complete(prefix, cursor_pos, c, prefix_match, subsequence_match); -} - void BufferManager::clear_buffer_trash() { while (not m_buffer_trash.empty()) diff --git a/src/buffer_manager.hh b/src/buffer_manager.hh index 5b0a37bc0..9d6edacc2 100644 --- a/src/buffer_manager.hh +++ b/src/buffer_manager.hh @@ -34,9 +34,6 @@ public: void backup_modified_buffers(); - CandidateList complete_buffer_name(StringView prefix, - ByteCount cursor_pos = -1); - void clear_buffer_trash(); private: BufferList m_buffers; diff --git a/src/commands.cc b/src/commands.cc index fb6a4975d..51e917f51 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -54,10 +54,26 @@ const PerArgumentCommandCompleter filename_completer({ cursor_pos) }; } }); +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 { + String name = buffer->display_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); + } + return name; + }); + return complete(prefix, cursor_pos, c, prefix_match, subsequence_match); +} + const PerArgumentCommandCompleter buffer_completer({ [](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos) - { return Completions{ 0_byte, cursor_pos, - BufferManager::instance().complete_buffer_name(prefix, cursor_pos) }; } + { return Completions{ 0_byte, cursor_pos, complete_buffer_name(prefix, cursor_pos) }; } }); const ParameterDesc no_params{ @@ -659,9 +675,8 @@ void define_command(const ParametersParser& parser, Context& context) size_t token_to_complete, ByteCount pos_in_token) { const String& prefix = params[token_to_complete]; - auto& bm = BufferManager::instance(); return Completions{ 0_byte, prefix.length(), - bm.complete_buffer_name(prefix, pos_in_token) }; + complete_buffer_name(prefix, pos_in_token) }; }; } else if (parser.has_option("shell-completion"))