Skip to content

Commit

Permalink
Revert "In buffer name completion, give priority to filename (not dir…
Browse files Browse the repository at this point in the history
…name) matches"

Buffer completions prefer matched file names over anything else.
For example

	kak -e 'e .git/rebase-merge/git-rebase-todo; edit -scratch *grep*; buffer *scratch*; exec ":b gre"'

shows .git/rebase-merge/git-rebase-todo before *grep* because the
basename ("git-rebase-todo") matches the query ("gre").

This works really well 90% of the time.  However, there are exceptions
like the example above. Maybe the new fuzzy matching is good enough
to be an overall improvement. Let's try to remove the special
treatement of file names for now.

This commit is experimental, I'll probably drop it.
  • Loading branch information
krobelus committed Jul 9, 2022
1 parent f31906d commit 947678a
Showing 1 changed file with 4 additions and 41 deletions.
45 changes: 4 additions & 41 deletions src/commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,48 +131,11 @@ template<bool ignore_current = false>
static Completions complete_buffer_name(const Context& context, CompletionFlags flags,
StringView prefix, ByteCount cursor_pos)
{
struct RankedMatchAndBuffer : RankedMatch
{
RankedMatchAndBuffer(RankedMatch m, const Buffer* b)
: RankedMatch{std::move(m)}, buffer{b} {}

using RankedMatch::operator==;
using RankedMatch::operator<;

const Buffer* buffer;
};

StringView query = prefix.substr(0, cursor_pos);
RankedMatchQuery q{query};
Vector<RankedMatchAndBuffer> filename_matches;
Vector<RankedMatchAndBuffer> matches;
for (const auto& buffer : BufferManager::instance())
{
if (ignore_current and buffer.get() == &context.buffer())
continue;

StringView bufname = buffer->display_name();
if (buffer->flags() & Buffer::Flags::File)
{
if (RankedMatch match{split_path(bufname).second, q})
{
filename_matches.emplace_back(match, buffer.get());
continue;
}
}
if (RankedMatch match{bufname, q})
matches.emplace_back(match, buffer.get());
}
std::sort(filename_matches.begin(), filename_matches.end());
std::sort(matches.begin(), matches.end());

CandidateList res;
for (auto& match : filename_matches)
res.push_back(match.buffer->display_name());
for (auto& match : matches)
res.push_back(match.buffer->display_name());
auto candidates = BufferManager::instance()
| transform([](const auto& buffer) -> const String&
{ return buffer->display_name(); });

return { 0, cursor_pos, res };
return { 0, cursor_pos, complete(prefix, cursor_pos, candidates) };
}

template<typename Func>
Expand Down

0 comments on commit 947678a

Please sign in to comment.