提交 8d6fd510 编写于 作者: A Alex Dima

Fixes #27459: Test first/last character in match if they are word separators...

Fixes #27459: Test first/last character in match if they are word separators besides the before/after characters
上级 83001adc
......@@ -405,23 +405,57 @@ export class TextModelSearch {
}
}
function isValidMatch(wordSeparators: WordCharacterClassifier, text: string, textLength: number, matchStartIndex: number, matchLength: number): boolean {
function leftIsWordBounday(wordSeparators: WordCharacterClassifier, text: string, textLength: number, matchStartIndex: number, matchLength: number): boolean {
if (matchStartIndex === 0) {
// Match starts at start of string
return true;
}
if (matchStartIndex - 1 >= 0) {
const charBefore = text.charCodeAt(matchStartIndex - 1);
if (wordSeparators.get(charBefore) === WordCharacterClass.Regular) {
return false;
const charBefore = text.charCodeAt(matchStartIndex - 1);
if (wordSeparators.get(charBefore) !== WordCharacterClass.Regular) {
// The character before the match is a word separator
return true;
}
if (matchLength > 0) {
const firstCharInMatch = text.charCodeAt(matchStartIndex);
if (wordSeparators.get(firstCharInMatch) !== WordCharacterClass.Regular) {
// The first character inside the match is a word separator
return true;
}
}
if (matchStartIndex + matchLength < textLength) {
const charAfter = text.charCodeAt(matchStartIndex + matchLength);
if (wordSeparators.get(charAfter) === WordCharacterClass.Regular) {
return false;
return false;
}
function rightIsWordBounday(wordSeparators: WordCharacterClassifier, text: string, textLength: number, matchStartIndex: number, matchLength: number): boolean {
if (matchStartIndex + matchLength === textLength) {
// Match ends at end of string
return true;
}
const charAfter = text.charCodeAt(matchStartIndex + matchLength);
if (wordSeparators.get(charAfter) !== WordCharacterClass.Regular) {
// The character after the match is a word separator
return true;
}
if (matchLength > 0) {
const lastCharInMatch = text.charCodeAt(matchStartIndex + matchLength - 1);
if (wordSeparators.get(lastCharInMatch) !== WordCharacterClass.Regular) {
// The last character in the match is a word separator
return true;
}
}
return true;
return false;
}
function isValidMatch(wordSeparators: WordCharacterClassifier, text: string, textLength: number, matchStartIndex: number, matchLength: number): boolean {
return (
leftIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength)
&& rightIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength)
);
}
class Searcher {
......
......@@ -354,6 +354,32 @@ suite('TextModelSearch', () => {
);
});
test('issue #27459: Match whole words regression', () => {
assertFindMatches(
[
'this._register(this._textAreaInput.onKeyDown((e: IKeyboardEvent) => {',
' this._viewController.emitKeyDown(e);',
'}));',
].join('\n'),
'((e: ', false, false, USUAL_WORD_SEPARATORS,
[
[1, 45, 1, 50]
]
);
});
test('issue #27594: Search results disappear', () => {
assertFindMatches(
[
'this.server.listen(0);',
].join('\n'),
'listen(', false, false, USUAL_WORD_SEPARATORS,
[
[1, 13, 1, 20]
]
);
});
test('findNextMatch without regex', () => {
let model = TextModel.createFromString('line line one\nline two\nthree');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册