提交 eb1d9729 编写于 作者: J Johannes Rieken

add option to allow for weak match as first match, use that option for outline (experiment) #50724

上级 424ac2e4
......@@ -454,7 +454,7 @@ const enum Arrow { Top = 0b1, Diag = 0b10, Left = 0b100 }
export type FuzzyScore = [number, number[]];
export function fuzzyScore(pattern: string, word: string, patternMaxWhitespaceIgnore?: number): FuzzyScore {
export function fuzzyScore(pattern: string, word: string, patternMaxWhitespaceIgnore?: number, firstMatchCanBeWeak?: boolean): FuzzyScore {
const patternLen = pattern.length > 100 ? 100 : pattern.length;
const wordLen = word.length > 100 ? 100 : word.length;
......@@ -578,6 +578,7 @@ export function fuzzyScore(pattern: string, word: string, patternMaxWhitespaceIg
_matchesCount = 0;
_topScore = -100;
_patternStartPos = patternStartPos;
_firstMatchCanBeWeak = firstMatchCanBeWeak;
_findAllMatches(patternLen, wordLen, patternLen === wordLen ? 1 : 0, new LazyArray(), false);
if (_matchesCount === 0) {
......@@ -591,6 +592,7 @@ let _matchesCount: number = 0;
let _topMatch: LazyArray;
let _topScore: number = 0;
let _patternStartPos: number = 0;
let _firstMatchCanBeWeak: boolean = false;
function _findAllMatches(patternPos: number, wordPos: number, total: number, matches: LazyArray, lastMatched: boolean): void {
......@@ -644,7 +646,7 @@ function _findAllMatches(patternPos: number, wordPos: number, total: number, mat
if (score === 1) {
simpleMatchCount += 1;
if (patternPos === _patternStartPos) {
if (patternPos === _patternStartPos && !_firstMatchCanBeWeak) {
// when the first match is a weak
// match we discard it
return undefined;
......
......@@ -309,6 +309,14 @@ suite('Filters', () => {
assertMatches('fo', 'bar\\foo', 'bar\\^f^oo', fuzzyScore);
});
test('fuzzyScore (first match can be weak)', function () {
let fuzzyScoreWeak = (pattern, word) => fuzzyScore(pattern, word, undefined, true);
assertMatches('Three', 'HTMLHRElement', 'H^TML^H^R^El^ement', fuzzyScoreWeak);
assertMatches('tor', 'constructor', 'construc^t^o^r', fuzzyScoreWeak);
assertMatches('ur', 'constructor', 'constr^ucto^r', fuzzyScoreWeak);
assertTopScore(fuzzyScoreWeak, 'tor', 2, 'constructor', 'Thor', 'cTor');
});
test('fuzzyScore, many matches', function () {
assertMatches(
......
......@@ -105,7 +105,7 @@ export class OutlineGroup extends TreeElement {
}
private _updateMatches(pattern: string, item: OutlineElement, topMatch: OutlineElement): OutlineElement {
item.score = fuzzyScore(pattern, item.symbol.name);
item.score = fuzzyScore(pattern, item.symbol.name, undefined, true);
if (item.score && (!topMatch || item.score[0] > topMatch.score[0])) {
topMatch = item;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册