From 08df409a534f6bfc5c53e9e4956f0f5aa973fc34 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 15 Mar 2018 23:20:03 +1100 Subject: [PATCH] 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 --- src/ranked_match.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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{[]()