From cc5fa9e647f6009d9c177173a879508958a23a85 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 10 Dec 2024 14:52:57 +0000 Subject: [PATCH] tweak to heuristic --- src/textual/fuzzy.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/textual/fuzzy.py b/src/textual/fuzzy.py index 6d5d1e4859..051431a33d 100644 --- a/src/textual/fuzzy.py +++ b/src/textual/fuzzy.py @@ -118,13 +118,13 @@ def score(search: _Search) -> float: """ # This is a heuristic, and can be tweaked for better results - # 2 points for a first letter, 1 for other letters + # Boost first letter matches score: float = sum( (2.0 if offset in first_letters else 1.0) for offset in search.offsets ) - # Divide by the number of groups - # 1 group no change, 2 groups score is halved etc. - score /= search.groups + # A single group gets a boost, as the user may be typing out an entire word + if search.groups == 1: + score *= 1.5 return score stack: list[_Search] = [_Search()]