Skip to content

Commit 9bbe0ef

Browse files
Bugfix in FuzzyCompleter.
1 parent d6fc71a commit 9bbe0ef

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

prompt_toolkit/completion/fuzzy_completer.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ class FuzzyWordCompleter(Completer):
2020
the others, because they match the regular expression 'o.*a.*r'.
2121
2222
The results are sorted by relevance, which is defined as the start position
23-
of the match and then the proportion of the word span that is covered. As a
24-
user, if you want to get leopard, it's better to type 'ld' (first + last
25-
letter) because this covers 100% of the word.
23+
and the length of the match.
2624
2725
See: https://blog.amjith.com/fuzzyfinder-in-10-lines-of-python
2826
@@ -61,12 +59,8 @@ def get_completions(self, document, complete_event):
6159
fuzzy_matches.append(_FuzzyMatch(len(best.group(1)), best.start(), word))
6260

6361
def sort_key(fuzzy_match):
64-
""" Sort by start position, then by proportion of word that is
65-
covered. (More coverage is better.) """
66-
return (
67-
fuzzy_match.start_pos,
68-
- float(fuzzy_match.match_length) / len(fuzzy_match.word)
69-
)
62+
" Sort by start position, then by the length of the match. "
63+
return fuzzy_match.start_pos, fuzzy_match.match_length
7064

7165
fuzzy_matches = sorted(fuzzy_matches, key=sort_key)
7266

0 commit comments

Comments
 (0)