Skip to content

Commit 0bc255b

Browse files
Don't count upper case bonus if the letters are consecutive (microsoft#135930)
* don't count upper case bonus if the letters are consecutive * update comment
1 parent 9eaf4c9 commit 0bc255b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/vs/base/common/fuzzyScorer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,11 @@ function computeCharScore(queryCharAtIndex: string, queryLowerCharAtIndex: strin
208208
// }
209209
}
210210

211-
// Inside word upper case bonus (camel case)
212-
else if (isUpper(target.charCodeAt(targetIndex))) {
211+
// Inside word upper case bonus (camel case). We only give this bonus if we're not in a contiguous sequence.
212+
// For example:
213+
// NPE => NullPointerException = boost
214+
// HTTP => HTTP = not boost
215+
else if (isUpper(target.charCodeAt(targetIndex)) && matchesSequenceLength === 0) {
213216
score += 2;
214217

215218
// if (DEBUG) {

src/vs/base/test/common/fuzzyScorer.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,13 @@ suite('Fuzzy Scorer', () => {
403403
}
404404
});
405405

406+
test('scoreItem - ensure upper case bonus only applies on non-consecutive matches (bug #134723)', function () {
407+
const resourceWithUpper = URI.file('ASDFasdfasdf');
408+
const resourceAllLower = URI.file('asdfasdfasdf');
409+
410+
assert.ok(scoreItem(resourceAllLower, 'asdf', true, ResourceAccessor).score > scoreItem(resourceWithUpper, 'asdf', true, ResourceAccessor).score);
411+
});
412+
406413
test('compareItemsByScore - identity', function () {
407414
const resourceA = URI.file('/some/path/fileA.txt');
408415
const resourceB = URI.file('/some/path/other/fileB.txt');

0 commit comments

Comments
 (0)