From 6ba28095df719abe429c1e3f4d32c52a454824d5 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Wed, 29 Aug 2018 22:17:23 -0700 Subject: [PATCH] #57418 also for builtin non-EH search --- src/vs/platform/search/common/search.ts | 5 +++-- .../platform/search/test/common/search.test.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/vs/platform/search/common/search.ts b/src/vs/platform/search/common/search.ts index 604f70a826dd0..f6efa5b224051 100644 --- a/src/vs/platform/search/common/search.ts +++ b/src/vs/platform/search/common/search.ts @@ -238,11 +238,12 @@ export class TextSearchResult implements ITextSearchResult { this.range = range; if (previewOptions) { const previewStart = Math.max(range.startColumn - previewOptions.leadingChars, 0); - const previewEnd = Math.max(previewOptions.totalChars + previewStart, range.endColumn); + const previewEnd = previewOptions.totalChars + previewStart; + const endOfMatchRangeInPreview = Math.min(previewEnd, range.endColumn - previewStart); this.preview = { text: fullLine.substring(previewStart, previewEnd), - match: new OneLineRange(0, range.startColumn - previewStart, range.endColumn - previewStart) + match: new OneLineRange(0, range.startColumn - previewStart, endOfMatchRangeInPreview) }; } else { this.preview = { diff --git a/src/vs/platform/search/test/common/search.test.ts b/src/vs/platform/search/test/common/search.test.ts index 28fe393b3cdcb..c56b87b33a831 100644 --- a/src/vs/platform/search/test/common/search.test.ts +++ b/src/vs/platform/search/test/common/search.test.ts @@ -94,4 +94,22 @@ suite('TextSearchResult', () => { range: new OneLineRange(5, 30, 33) }); }); + + test('truncating match', () => { + const previewOptions: ITextSearchPreviewOptions = { + leadingChars: 4, + maxLines: 1, + totalChars: 5 + }; + + assert.deepEqual( + new TextSearchResult('foo bar', new OneLineRange(0, 4, 7), previewOptions), + { + preview: { + text: 'foo b', + match: new OneLineRange(0, 4, 5) + }, + range: new OneLineRange(0, 4, 7) + }); + }); }); \ No newline at end of file