From 960441f3b2799cc459ced19289e447cc6049d30f Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Thu, 3 Aug 2023 00:28:46 +0200 Subject: [PATCH] Deprioritize camel case This change avoids scoring camel case higher than other casing --- matcher/src/score.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/matcher/src/score.rs b/matcher/src/score.rs index 05e591c..b3321d3 100644 --- a/matcher/src/score.rs +++ b/matcher/src/score.rs @@ -16,9 +16,15 @@ pub(crate) const PENALTY_GAP_EXTENSION: u16 = 1; pub(crate) const BONUS_BOUNDARY: u16 = SCORE_MATCH / 2; // Edge-triggered bonus for matches in camelCase words. -// Compared to word-boundary case, they don't accompany single-character gaps -// (e.g. FooBar vs. foo-bar), so we deduct bonus point accordingly. -pub(crate) const BONUS_CAMEL123: u16 = BONUS_BOUNDARY - PENALTY_GAP_EXTENSION; +// Their value should be BONUS_BOUNDARY - PENALTY_GAP_EXTENSION = 7. +// However, this priporitzes camel case over non-camel case. +// In fzf/skim this is not a problem since they score off the max +// consecutive bounus. However, we don't do that (because its incorrect) +// so to avoids prioritzing camel we use a lower bonus. I think that's fine +// usually camel case is wekaer boundary than actual wourd boundaries anyway +// This also has the nice sideeffect of perfectly balancing out +// camel case, snake case and the consecutive version of the word +pub(crate) const BONUS_CAMEL123: u16 = BONUS_CONSECUTIVE; // Minimum bonus point given to characters in consecutive chunks. // Note that bonus points for consecutive matches shouldn't have needed if we