From afc8f3903f44cb931fbe2940d741b04d488fda7c Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Wed, 29 Jun 2016 16:56:43 +0200 Subject: [PATCH] fix #8335 --- .../parts/search/browser/replaceService.ts | 13 ++++++++++--- src/vs/workbench/parts/search/common/searchModel.ts | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/parts/search/browser/replaceService.ts b/src/vs/workbench/parts/search/browser/replaceService.ts index 6d8da3c0fea..546febfef28 100644 --- a/src/vs/workbench/parts/search/browser/replaceService.ts +++ b/src/vs/workbench/parts/search/browser/replaceService.ts @@ -23,10 +23,12 @@ import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; class EditorInputCache { private cache: Map.SimpleMap>; + private replaceTextcache: Map.SimpleMap; constructor(private replaceService: ReplaceService, private editorService: IWorkbenchEditorService, private modelService: IModelService) { this.cache= new Map.SimpleMap>(); + this.replaceTextcache= new Map.SimpleMap(); } public getInput(fileMatch: FileMatch, text: string): TPromise { @@ -36,6 +38,7 @@ class EditorInputCache { this.cache.set(fileMatch.resource(), editorInputPromise); this.refreshInput(fileMatch, text, true); fileMatch.addListener2('disposed', fileMatch => this.disposeInput(fileMatch)); + fileMatch.addListener2('changed', fileMatch => this.refreshInput(fileMatch, this.replaceTextcache.get(fileMatch.resource()), false)); } return editorInputPromise; } @@ -55,6 +58,7 @@ class EditorInputCache { this.modelService.getModel(replaceResource).undo(); this.replaceService.replace(fileMatch, text, null, replaceResource); } + this.replaceTextcache.set(fileMatch.resource(), text); }); } } @@ -69,6 +73,7 @@ class EditorInputCache { editorInputPromise.done((diffInput) => { this.disposeReplaceInput(this.getReplaceResource(resourceUri), diffInput); this.cache.delete(resourceUri); + this.replaceTextcache.delete(resourceUri); }); } } @@ -141,9 +146,11 @@ export class ReplaceService implements IReplaceService { if (arg instanceof Array) { arg.forEach(element => { let fileMatch = element; - fileMatch.matches().forEach(match => { - bulkEdit.add([this.createEdit(match, text, resource)]); - }); + if (fileMatch.count() > 0) { + fileMatch.matches().forEach(match => { + bulkEdit.add([this.createEdit(match, text, resource)]); + }); + } }); } diff --git a/src/vs/workbench/parts/search/common/searchModel.ts b/src/vs/workbench/parts/search/common/searchModel.ts index c321ca7afbd..bb861512b7c 100644 --- a/src/vs/workbench/parts/search/common/searchModel.ts +++ b/src/vs/workbench/parts/search/common/searchModel.ts @@ -98,6 +98,7 @@ export class FileMatch extends EventEmitter implements lifecycle.IDisposable { public add(match: Match): void { this._matches[match.id()] = match; + this.emit('changed', this); } public remove(match: Match): void { @@ -106,6 +107,7 @@ export class FileMatch extends EventEmitter implements lifecycle.IDisposable { if (this.count() === 0) { this.add(new EmptyMatch(this)); } + this.emit('changed', this); } public matches(): Match[] { @@ -217,6 +219,10 @@ export class LiveFileMatch extends FileMatch implements lifecycle.IDisposable { return !this._model || (this._model).isDisposed(); } + public remove(match: Match): void { + super.remove(match); + this._diskFileMatch.remove(match); + } } export class SearchResult extends EventEmitter { -- GitLab