Unified · Split
| @@ -13,6 +13,8 @@ fuzzyRegexp = # query fuzzy regexp · 12 unmodified lines | ||
| 13 | 13 | index = # position of the query in the string being matched |
| 14 | 14 | lastIndex = # last position of the query in the string being matched |
| 15 | 15 | match = # regexp match data |
| 16 | +matchIndex = | |
| 17 | +matchLength = | |
| 16 | 18 | score = # score for the current match |
| 17 | 19 | separators = # counter |
| 18 | 20 | i = null # cursor |
| @@ -74,16 +76,27 @@ return Math.max 1, score · 55 unmodified lines | ||
| 74 | 76 | `function fuzzyMatch() {` |
| 75 | 77 | return if valueLength <= queryLength or value.indexOf(query) >= 0 |
| 76 | 78 | return unless match = fuzzyRegexp.exec(value) |
| 79 | +matchIndex = match.index | |
| 80 | +matchLength = match[0].length | |
| 81 | +score = scoreFuzzyMatch() | |
| 82 | +if match = fuzzyRegexp.exec(value.slice(i = value.lastIndexOf(SEPARATOR) + 1)) | |
| 83 | + matchIndex = i + match.index | |
| 84 | + matchLength = match[0].length | |
| 85 | + return Math.max(score, scoreFuzzyMatch()) | |
| 86 | +else | |
| 87 | + return score | |
| 88 | +`}` | |
| 77 | 89 | |
| 90 | +`function scoreFuzzyMatch() {` | |
| 78 | 91 | # When the match is at the beginning of the string or preceded by a dot. |
| 79 | −if match.index is 0 or value.charAt(match.index - 1) is SEPARATOR | |
| 80 | − return Math.max 66, 100 - match[0].length | |
| 92 | +if matchIndex is 0 or value.charAt(matchIndex - 1) is SEPARATOR | |
| 93 | + return Math.max 66, 100 - matchLength | |
| 81 | 94 | # When the match is at the end of the string. |
| 82 | −else if match.index + match[0].length is valueLength | |
| 83 | − return Math.max 33, 67 - match[0].length | |
| 95 | +else if matchIndex + matchLength is valueLength | |
| 96 | + return Math.max 33, 67 - matchLength | |
| 84 | 97 | # When the match is in the middle of the string. |
| 85 | 98 | else |
| 86 | − return Math.max 1, 34 - match[0].length | |
| 99 | + return Math.max 1, 34 - matchLength | |
| 87 | 100 | `}` |
| 88 | 101 | |
| 89 | 102 | # |