提交 08cf6e91 编写于 作者: S Sandeep Somavarapu

Fix #20058

上级 9af9a80a
......@@ -25,6 +25,16 @@ import { IModel } from 'vs/editor/common/editorCommon';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IFileService } from 'vs/platform/files/common/files';
const REPLACE_PREVIEW = 'replacePreview';
const toReplaceResource = (fileResource: URI): URI => {
return fileResource.with({ scheme: network.Schemas.internal, fragment: REPLACE_PREVIEW, query: JSON.stringify({ scheme: fileResource.scheme }) });
};
const toFileResource = (replaceResource: URI): URI => {
return replaceResource.with({ scheme: JSON.parse(replaceResource.query)['scheme'], fragment: '', query: '' });
};
export class ReplacePreviewContentProvider implements ITextModelContentProvider, IWorkbenchContribution {
constructor(
......@@ -39,7 +49,7 @@ export class ReplacePreviewContentProvider implements ITextModelContentProvider,
}
public provideTextContent(uri: URI): TPromise<IModel> {
if (uri.fragment === 'preview') {
if (uri.fragment === REPLACE_PREVIEW) {
return this.instantiationService.createInstance(ReplacePreviewModel).resolve(uri);
}
return null;
......@@ -58,7 +68,7 @@ class ReplacePreviewModel extends Disposable {
}
resolve(replacePreviewUri: URI): TPromise<IModel> {
const fileResource = replacePreviewUri.with({ scheme: network.Schemas.file, fragment: '' });
const fileResource = toFileResource(replacePreviewUri);
const fileMatch = <FileMatch>this.searchWorkbenchService.searchModel.searchResult.matches().filter(match => match.resource().toString() === fileResource.toString())[0];
return this.textModelResolverService.createModelReference(fileResource).then(ref => {
ref = this._register(ref);
......@@ -132,7 +142,7 @@ export class ReplaceService implements IReplaceService {
return this.editorService.openEditor({
leftResource: fileMatch.resource(),
rightResource: this.getReplacePreviewUri(fileMatch),
rightResource: toReplaceResource(fileMatch.resource()),
label: nls.localize('fileReplaceChanges', "{0} ↔ {1} (Replace Preview)", fileMatch.name(), fileMatch.name()),
options: {
preserveFocus,
......@@ -150,7 +160,7 @@ export class ReplaceService implements IReplaceService {
}
public updateReplacePreview(fileMatch: FileMatch, override: boolean = false): TPromise<void> {
const replacePreviewUri = this.getReplacePreviewUri(fileMatch);
const replacePreviewUri = toReplaceResource(fileMatch.resource());
return TPromise.join([this.textModelResolverService.createModelReference(fileMatch.resource()), this.textModelResolverService.createModelReference(replacePreviewUri)])
.then(([sourceModelRef, replaceModelRef]) => {
const sourceModel = sourceModelRef.object.textEditorModel;
......@@ -181,8 +191,4 @@ export class ReplaceService implements IReplaceService {
};
return resourceEdit;
}
private getReplacePreviewUri(fileMatch: FileMatch): URI {
return fileMatch.resource().with({ scheme: network.Schemas.internal, fragment: 'preview' });
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册