From cea939e88955f0d7bc5aadac0f2fa81285a4a4d5 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Tue, 11 Sep 2018 19:04:02 -0700 Subject: [PATCH] Fix #58374 --- src/vs/workbench/parts/search/browser/searchView.ts | 9 ++++++++- src/vs/workbench/parts/search/common/searchModel.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/parts/search/browser/searchView.ts b/src/vs/workbench/parts/search/browser/searchView.ts index 7dc0e16dfdd..399e95f0a42 100644 --- a/src/vs/workbench/parts/search/browser/searchView.ts +++ b/src/vs/workbench/parts/search/browser/searchView.ts @@ -1078,6 +1078,13 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { const excludePattern = this.inputPatternExcludes.getValue(); const includePattern = this.inputPatternIncludes.getValue(); + // Need the full match line to correctly calculate replace text, if this is a search/replace with regex group references ($1, $2, ...). + // 10000 chars is enough to avoid sending huge amounts of text around, if you do a replace with a longer match, it may or may not resolve the group refs correctly. + // https://github.com/Microsoft/vscode/issues/58374 + const totalChars = content.isRegExp ? 10000 : + this.isWide ? 250 : + 75; + const options: IQueryOptions = { extraFileResources: getOutOfWorkspaceEditorResources(this.editorService, this.contextService), maxResults: SearchView.MAX_TEXT_RESULTS, @@ -1088,7 +1095,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { previewOptions: { leadingChars: 20, maxLines: 1, - totalChars: this.isWide ? 250 : 75 + totalChars } }; const folderResources = this.contextService.getWorkspace().folders; diff --git a/src/vs/workbench/parts/search/common/searchModel.ts b/src/vs/workbench/parts/search/common/searchModel.ts index 8050a8c6939..b3fe7530db6 100644 --- a/src/vs/workbench/parts/search/common/searchModel.ts +++ b/src/vs/workbench/parts/search/common/searchModel.ts @@ -27,6 +27,8 @@ import { IReplaceService } from 'vs/workbench/parts/search/common/replace'; export class Match { + private static readonly MAX_PREVIEW_CHARS = 250; + private _id: string; private _range: Range; private _previewText: string; @@ -66,10 +68,15 @@ export class Match { } public preview(): { before: string; inside: string; after: string; } { - const before = this._previewText.substring(0, this._rangeInPreviewText.startColumn - 1), + let before = this._previewText.substring(0, this._rangeInPreviewText.startColumn - 1), inside = this.getMatchString(), after = this._previewText.substring(this._rangeInPreviewText.endColumn - 1); + let charsRemaining = Match.MAX_PREVIEW_CHARS - before.length; + inside = inside.substr(0, charsRemaining); + charsRemaining -= inside.length; + after = after.substr(0, charsRemaining); + return { before, inside, -- GitLab