提交 86fa120c 编写于 作者: R Rob Lourens

Fix #81129

上级 a817a588
......@@ -107,12 +107,12 @@ export class Match {
// If match string is not matching then regex pattern has a lookahead expression
if (replaceString === null) {
const fullMatchTextWithTrailingContent = this.fullMatchText(true);
replaceString = searchModel.replacePattern.getReplaceString(fullMatchTextWithTrailingContent, searchModel.preserveCase);
const fullMatchTextWithSurroundingContent = this.fullMatchText(true);
replaceString = searchModel.replacePattern.getReplaceString(fullMatchTextWithSurroundingContent, searchModel.preserveCase);
// Search/find normalize line endings - check whether \r prevents regex from matching
if (replaceString === null) {
const fullMatchTextWithoutCR = fullMatchTextWithTrailingContent.replace(/\r\n/g, '\n');
const fullMatchTextWithoutCR = fullMatchTextWithSurroundingContent.replace(/\r\n/g, '\n');
replaceString = searchModel.replacePattern.getReplaceString(fullMatchTextWithoutCR, searchModel.preserveCase);
}
}
......@@ -125,17 +125,16 @@ export class Match {
return replaceString;
}
fullMatchText(includeTrailing = false): string {
fullMatchText(includeSurrounding = false): string {
let thisMatchPreviewLines: string[];
if (includeTrailing) {
thisMatchPreviewLines = this._fullPreviewLines.slice(this._fullPreviewRange.startLineNumber);
if (includeSurrounding) {
thisMatchPreviewLines = this._fullPreviewLines;
} else {
thisMatchPreviewLines = this._fullPreviewLines.slice(this._fullPreviewRange.startLineNumber, this._fullPreviewRange.endLineNumber + 1);
thisMatchPreviewLines[thisMatchPreviewLines.length - 1] = thisMatchPreviewLines[thisMatchPreviewLines.length - 1].slice(0, this._fullPreviewRange.endColumn);
thisMatchPreviewLines[0] = thisMatchPreviewLines[0].slice(this._fullPreviewRange.startColumn);
}
thisMatchPreviewLines[0] = thisMatchPreviewLines[0].slice(this._fullPreviewRange.startColumn);
return thisMatchPreviewLines.join('\n');
}
......
......@@ -33,16 +33,16 @@ suite('SearchResult', () => {
test('Line Match', function () {
const fileMatch = aFileMatch('folder/file.txt', null!);
const lineMatch = new Match(fileMatch, ['foo bar'], new OneLineRange(0, 0, 3), new OneLineRange(1, 0, 3));
assert.equal(lineMatch.text(), 'foo bar');
const lineMatch = new Match(fileMatch, ['0 foo bar'], new OneLineRange(0, 2, 5), new OneLineRange(1, 0, 5));
assert.equal(lineMatch.text(), '0 foo bar');
assert.equal(lineMatch.range().startLineNumber, 2);
assert.equal(lineMatch.range().endLineNumber, 2);
assert.equal(lineMatch.range().startColumn, 1);
assert.equal(lineMatch.range().endColumn, 4);
assert.equal('file:///folder/file.txt>[2,1 -> 2,4]foo', lineMatch.id());
assert.equal(lineMatch.range().endColumn, 6);
assert.equal(lineMatch.id(), 'file:///folder/file.txt>[2,1 -> 2,6]foo');
assert.equal(lineMatch.fullMatchText(), 'foo');
assert.equal(lineMatch.fullMatchText(true), 'foo bar');
assert.equal(lineMatch.fullMatchText(true), '0 foo bar');
});
test('Line Match - Remove', function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册