Skip to content

Commit

Permalink
search: fix copy all containing extraneous crlf line endings
Browse files Browse the repository at this point in the history
Fixes #65348
  • Loading branch information
connor4312 committed Nov 13, 2020
1 parent fbaf7b1 commit 5da5495
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/vs/base/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,15 @@ export function getNLines(str: string, n = 1): string {
n--;
} while (n > 0 && idx >= 0);

return idx >= 0 ?
str.substr(0, idx) :
str;
if (idx === -1) {
return str;
}

if (str[idx - 1] === '\r') {
idx--;
}

return str.substr(0, idx);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/vs/workbench/services/search/test/common/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ suite('TextSearchResult', () => {
assert.equal(result.preview.text, 'foo bar 123456⟪ 117 characters skipped ⟫o bar baz bar');
});

test('trims lines endings', () => {
const range = new SearchRange(5, 3, 5, 5);
const previewOptions: ITextSearchPreviewOptions = {
matchLines: 1,
charsPerLine: 10000
};

assert.equal(new TextSearchMatch('foo bar\n', range, previewOptions).preview.text, 'foo bar');
assert.equal(new TextSearchMatch('foo bar\r\n', range, previewOptions).preview.text, 'foo bar');
});

// test('all lines of multiline match', () => {
// const previewOptions: ITextSearchPreviewOptions = {
// matchLines: 5,
Expand Down

0 comments on commit 5da5495

Please sign in to comment.