Skip to content

Commit 86fa120

Browse files
committed
1 parent a817a58 commit 86fa120

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/vs/workbench/contrib/search/common/searchModel.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ export class Match {
107107

108108
// If match string is not matching then regex pattern has a lookahead expression
109109
if (replaceString === null) {
110-
const fullMatchTextWithTrailingContent = this.fullMatchText(true);
111-
replaceString = searchModel.replacePattern.getReplaceString(fullMatchTextWithTrailingContent, searchModel.preserveCase);
110+
const fullMatchTextWithSurroundingContent = this.fullMatchText(true);
111+
replaceString = searchModel.replacePattern.getReplaceString(fullMatchTextWithSurroundingContent, searchModel.preserveCase);
112112

113113
// Search/find normalize line endings - check whether \r prevents regex from matching
114114
if (replaceString === null) {
115-
const fullMatchTextWithoutCR = fullMatchTextWithTrailingContent.replace(/\r\n/g, '\n');
115+
const fullMatchTextWithoutCR = fullMatchTextWithSurroundingContent.replace(/\r\n/g, '\n');
116116
replaceString = searchModel.replacePattern.getReplaceString(fullMatchTextWithoutCR, searchModel.preserveCase);
117117
}
118118
}
@@ -125,17 +125,16 @@ export class Match {
125125
return replaceString;
126126
}
127127

128-
fullMatchText(includeTrailing = false): string {
128+
fullMatchText(includeSurrounding = false): string {
129129
let thisMatchPreviewLines: string[];
130-
if (includeTrailing) {
131-
thisMatchPreviewLines = this._fullPreviewLines.slice(this._fullPreviewRange.startLineNumber);
130+
if (includeSurrounding) {
131+
thisMatchPreviewLines = this._fullPreviewLines;
132132
} else {
133133
thisMatchPreviewLines = this._fullPreviewLines.slice(this._fullPreviewRange.startLineNumber, this._fullPreviewRange.endLineNumber + 1);
134134
thisMatchPreviewLines[thisMatchPreviewLines.length - 1] = thisMatchPreviewLines[thisMatchPreviewLines.length - 1].slice(0, this._fullPreviewRange.endColumn);
135-
135+
thisMatchPreviewLines[0] = thisMatchPreviewLines[0].slice(this._fullPreviewRange.startColumn);
136136
}
137137

138-
thisMatchPreviewLines[0] = thisMatchPreviewLines[0].slice(this._fullPreviewRange.startColumn);
139138
return thisMatchPreviewLines.join('\n');
140139
}
141140

src/vs/workbench/contrib/search/test/common/searchResult.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ suite('SearchResult', () => {
3333

3434
test('Line Match', function () {
3535
const fileMatch = aFileMatch('folder/file.txt', null!);
36-
const lineMatch = new Match(fileMatch, ['foo bar'], new OneLineRange(0, 0, 3), new OneLineRange(1, 0, 3));
37-
assert.equal(lineMatch.text(), 'foo bar');
36+
const lineMatch = new Match(fileMatch, ['0 foo bar'], new OneLineRange(0, 2, 5), new OneLineRange(1, 0, 5));
37+
assert.equal(lineMatch.text(), '0 foo bar');
3838
assert.equal(lineMatch.range().startLineNumber, 2);
3939
assert.equal(lineMatch.range().endLineNumber, 2);
4040
assert.equal(lineMatch.range().startColumn, 1);
41-
assert.equal(lineMatch.range().endColumn, 4);
42-
assert.equal('file:///folder/file.txt>[2,1 -> 2,4]foo', lineMatch.id());
41+
assert.equal(lineMatch.range().endColumn, 6);
42+
assert.equal(lineMatch.id(), 'file:///folder/file.txt>[2,1 -> 2,6]foo');
4343

4444
assert.equal(lineMatch.fullMatchText(), 'foo');
45-
assert.equal(lineMatch.fullMatchText(true), 'foo bar');
45+
assert.equal(lineMatch.fullMatchText(true), '0 foo bar');
4646
});
4747

4848
test('Line Match - Remove', function () {

0 commit comments

Comments
 (0)