Skip to content

Commit

Permalink
#57418 also for builtin non-EH search
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Aug 30, 2018
1 parent bc784b6 commit 6ba2809
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/vs/platform/search/common/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
18 changes: 18 additions & 0 deletions src/vs/platform/search/test/common/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
<ITextSearchResult>{
preview: {
text: 'foo b',
match: new OneLineRange(0, 4, 5)
},
range: new OneLineRange(0, 4, 7)
});
});
});

0 comments on commit 6ba2809

Please sign in to comment.