summaryrefslogtreecommitdiff
path: root/src/ranked_match.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-03-15 23:20:03 +1100
committerMaxime Coste <mawww@kakoune.org>2018-03-15 23:20:03 +1100
commit08df409a534f6bfc5c53e9e4956f0f5aa973fc34 (patch)
treea3367da6b15c2b94517030db5e713e8a487c5fe9 /src/ranked_match.cc
parent1ede2b89bbb0c8b85eb48d072ad57943706729dd (diff)
RankedMatch: Do not compare word boundary match count on single word matches
As the computation of word boundary matches is separate from the actual subsequence matching, we sometimes have candidate that match as a single word while still having multiple word boundary matches. For example, with query "expresins", candidate "expressionism's" will match as single word ("expressins" is a subsequence of "expressionism"), and will have two word boundaries match (it does match the last "s", which is considered as a separate word). This should not be taken into account when compared against candidate "expresions", which should be considered a better match. Fixes #1925
Diffstat (limited to 'src/ranked_match.cc')
-rw-r--r--src/ranked_match.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/ranked_match.cc b/src/ranked_match.cc
index 03f366c7..423fc814 100644
--- a/src/ranked_match.cc
+++ b/src/ranked_match.cc
@@ -180,7 +180,9 @@ bool RankedMatch::operator<(const RankedMatch& other) const
if (diff != Flags::None)
return (int)(m_flags & diff) > (int)(other.m_flags & diff);
- if (not (m_flags & Flags::Prefix) and
+ // If we are SingleWord, FirstCharMatch will do the job, and we dont want to take
+ // other words boundaries into account.
+ if (not (m_flags & (Flags::Prefix | Flags::SingleWord)) and
m_word_boundary_match_count != other.m_word_boundary_match_count)
return m_word_boundary_match_count > other.m_word_boundary_match_count;
@@ -241,6 +243,7 @@ UnitTest test_ranked_match{[] {
kak_assert(RankedMatch{"class", "cla"} < RankedMatch{"class::attr", "cla"});
kak_assert(RankedMatch{"meta/", "meta"} < RankedMatch{"meta-a/", "meta"});
kak_assert(RankedMatch{"find(1p)", "find"} < RankedMatch{"findfs(8)", "find"});
+ kak_assert(RankedMatch{"expresions", "expresins"} < RankedMatch{"expressionism's", "expresins"});
}};
UnitTest test_used_letters{[]()