Skip to content

Commit

Permalink
fixed small bug in fuzzy matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Mar 23, 2024
1 parent 3ba3425 commit 2937432
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/misc/fuzzy_matching.nim
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ type
ignoredChars: set[char] = {'_', ' ', '.'}
maxRecursionLevel: int = 4

const defaultPathMatchingConfig* = FuzzyMatchConfig()
const defaultPathMatchingConfig* = FuzzyMatchConfig(ignoredChars: {' '})
const defaultCompletionMatchingConfig* = FuzzyMatchConfig(ignoredChars: {' '})

proc matchFuzzySublime*(pattern, str: openArray[char], matches: var seq[int], recordMatches: bool, config: FuzzyMatchConfig = FuzzyMatchConfig(), recursionLevel: int = 0, baseIndex: int = 0): tuple[score: int, matched: bool]
Expand Down Expand Up @@ -221,17 +221,17 @@ proc matchFuzzySublime*(pattern, str: openArray[char], matches: var seq[int], re
continue

if strChar == patternChar:
if recordMatches:
matches.add(strIndex + baseIndex)

if recursionLevel < config.maxRecursionLevel and strIndex + 1 < str.len:
var tempMatches: seq[int]
var tempMatches: seq[int] = matches
let tempScore = matchFuzzySublime(pattern[patIndex..^1], str[(strIndex + 1)..^1], tempMatches, recordMatches, config, recursionLevel + 1, baseIndex + strIndex + 1).score
if tempScore > bestRecursionScore:
bestRecursionScore = tempScore
if recordMatches:
bestRecursionMatches = move tempMatches

if recordMatches:
matches.add(strIndex + baseIndex)

case scoreState
of StartMatch, WordBoundryMatch:
scoreState = LeadingCharMatch
Expand Down

0 comments on commit 2937432

Please sign in to comment.