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

boost prefix-matches, #22153

上级 5f58fd5e
......@@ -555,7 +555,13 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
score = 5;
} else if (j === 1) {
score = 5;
if (pattern[i - 1] === word[j - 1]) {
score = 7;
} else {
score = 5;
}
} else if (j === i) {
score = 3;
} else {
score = 1;
......@@ -619,6 +625,7 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
// keep going left, we cannot
// skip a character in the pattern
j -= 1;
total -= 1;
} else if (arrow === 0) { //diag
j -= 1;
......@@ -635,6 +642,7 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
// we went diagonal by inheriting a good
// result, not by matching keep going left
i += 1;
total -= 1;
} else {
// all good
......@@ -654,8 +662,6 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
j = 3;
}
total -= j * 3; // penalty for first matching character
total -= (1 + matches[matches.length - 1]) - (pattern.length); // penalty for all non matching characters between first and last
if (_debug) {
console.log(`${pattern} & ${word} => ${total} points for ${matches}`);
......
......@@ -279,6 +279,8 @@ suite('Filters', () => {
assertMatches('ob', 'foobar', undefined, fuzzyScore);
assertMatches('sl', 'SVisualLoggerLogsList', '^SVisual^LoggerLogsList', fuzzyScore);
assertMatches('sllll', 'SVisualLoggerLogsList', '^SVisua^l^Logger^Logs^List', fuzzyScore);
assertMatches('Three', 'HTMLHRElement', 'H^TML^H^R^El^ement', fuzzyScore);
assertMatches('Three', 'Three', '^T^h^r^e^e', fuzzyScore);
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册