Skip to content

Commit

Permalink
fix #28791
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jun 15, 2017
1 parent 77bdf51 commit a248e33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/vs/base/common/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,20 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
let patternPos = patternStartPos;
let wordPos = 0;

// Run a simple check if the characters of pattern occur
// (in order) at all in word. If that isn't the case we
// stop because no match will be possible
while (patternPos < patternLen && wordPos < wordLen) {
if (lowPattern[patternPos] === lowWord[wordPos]) {
patternPos += 1;
}
wordPos += 1;
}
if (patternPos !== patternLen) {
// no simple matches found -> return early
return undefined;
}

// There will be a mach, fill in tables
for (patternPos = patternStartPos + 1; patternPos <= patternLen; patternPos++) {

let lastLowWordChar = '';
Expand All @@ -483,20 +486,22 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
let score = -1;
let lowWordChar = lowWord[wordPos - 1];
if (lowPattern[patternPos - 1] === lowWordChar) {

if (wordPos === 1) {
if (wordPos === (patternPos - patternStartPos)) {
// common prefix: `foobar <-> foobaz`
if (pattern[patternPos - 1] === word[wordPos - 1]) {
score = 7;
} else {
score = 5;
}
} else if (lowWordChar !== word[wordPos - 1]) {
// hitting upper-case: `foo <-> forOthers`
if (pattern[patternPos - 1] === word[wordPos - 1]) {
score = 7;
} else {
score = 5;
}
} else if (_seps[lastLowWordChar]) {
// post separator: `foo <-> bar_foo`
score = 5;

} else {
Expand Down
8 changes: 5 additions & 3 deletions src/vs/base/test/common/filters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,11 @@ suite('Filters', () => {
assertTopScore(fuzzyScore, 'title', 1, 'files.trimTrailingWhitespace', 'window.title');
});

// test('Unexpected suggestion scoring, #28791', function () {
// assertTopScore(fuzzyScore, '_lines', 1, '_lineStarts', '_lines');
// });
test('Unexpected suggestion scoring, #28791', function () {
assertTopScore(fuzzyScore, '_lines', 1, '_lineStarts', '_lines');
assertTopScore(fuzzyScore, '_lines', 1, '_lineS', '_lines');
assertTopScore(fuzzyScore, '_lineS', 0, '_lineS', '_lines');
});

test('nextTypoPermutation', function () {

Expand Down

0 comments on commit a248e33

Please sign in to comment.