From 610113860629f2297c1a09f2038fe47ce6a18b3a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 4 Jun 2017 08:27:53 +0100 Subject: [PATCH] Change RankedMatch ordering to favor `/` characters This will improve matching of filenames, as 'foo/' will be sorted before 'foo-bar' due to `/` coming before `-` in the new ordering (it comes after in ascii/unicode order). Fixes #1395 --- src/ranked_match.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ranked_match.cc b/src/ranked_match.cc index 3b1d9645..4df3792d 100644 --- a/src/ranked_match.cc +++ b/src/ranked_match.cc @@ -182,6 +182,9 @@ bool RankedMatch::operator<(const RankedMatch& other) const if (m_max_index != other.m_max_index) return m_max_index < other.m_max_index; + // Reorder codepoints to improve matching behaviour + auto order = [](Codepoint cp) { return cp == '/' ? 0 : cp; }; + auto it1 = m_candidate.begin(), it2 = other.m_candidate.begin(); const auto end1 = m_candidate.end(), end2 = other.m_candidate.end(); auto last1 = it1, last2 = it2; @@ -203,7 +206,7 @@ bool RankedMatch::operator<(const RankedMatch& other) const { const bool low1 = iswlower((wchar_t)cp1); const bool low2 = iswlower((wchar_t)cp2); - return low1 == low2 ? cp1 < cp2 : low1; + return low1 == low2 ? order(cp1) < order(cp2) : low1; } last1 = it1; last2 = it2; } @@ -223,6 +226,7 @@ UnitTest test_ranked_match{[] { kak_assert(RankedMatch{"delete-buffer", "db"} < RankedMatch{"debug", "db"}); kak_assert(RankedMatch{"create_task", "ct"} < RankedMatch{"constructor", "ct"}); kak_assert(RankedMatch{"class", "cla"} < RankedMatch{"class::attr", "cla"}); + kak_assert(RankedMatch{"meta/", "meta"} < RankedMatch{"meta-a/", "meta"}); }}; UnitTest test_used_letters{[]()