Skip to content

Commit 3d99a60

Browse files
committed
Make leftie editable in replace preview diff editor
1 parent 096e2b5 commit 3d99a60

4 files changed

Lines changed: 31 additions & 14 deletions

File tree

src/vs/base/common/network.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ export namespace Schemas {
1414
*/
1515
export var inMemory:string = 'inmemory';
1616

17+
/**
18+
* A schema that is used for setting files
19+
*/
20+
export var vscode:string = 'vscode';
21+
22+
/**
23+
* A schema that is used for internal private files
24+
*/
25+
export var internal:string = 'private';
26+
1727
export var http:string = 'http';
1828

1929
export var https:string = 'https';

src/vs/workbench/browser/actions/openSettings.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import {TPromise} from 'vs/base/common/winjs.base';
88
import nls = require('vs/nls');
99
import URI from 'vs/base/common/uri';
10+
import network = require('vs/base/common/network');
1011
import labels = require('vs/base/common/labels');
1112
import {Registry} from 'vs/platform/platform';
1213
import {Action} from 'vs/base/common/actions';
@@ -217,7 +218,7 @@ class DefaultSettingsInput extends StringEditorInput {
217218
}
218219

219220
protected getResource(): URI {
220-
return URI.from({ scheme: 'vscode', authority: 'defaultsettings', path: '/settings.json' }); // URI is used to register JSON schema support
221+
return URI.from({ scheme: network.Schemas.vscode, authority: 'defaultsettings', path: '/settings.json' }); // URI is used to register JSON schema support
221222
}
222223
}
223224

@@ -236,7 +237,7 @@ class DefaultKeybindingsInput extends StringEditorInput {
236237
}
237238

238239
protected getResource(): URI {
239-
return URI.from({ scheme: 'vscode', authority: 'defaultsettings', path: '/keybindings.json' }); // URI is used to register JSON schema support
240+
return URI.from({ scheme: network.Schemas.vscode, authority: 'defaultsettings', path: '/keybindings.json' }); // URI is used to register JSON schema support
240241
}
241242
}
242243

src/vs/workbench/parts/search/browser/replaceService.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import nls = require('vs/nls');
77
import { TPromise } from 'vs/base/common/winjs.base';
88
import URI from 'vs/base/common/uri';
9+
import * as network from 'vs/base/common/network';
910
import * as Map from 'vs/base/common/map';
1011
import { IReplaceService } from 'vs/workbench/parts/search/common/replace';
1112
import { EditorInput } from 'vs/workbench/common/editor';
1213
import { IEditorService, IEditorInput, ITextEditorModel } from 'vs/platform/editor/common/editor';
14+
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
1315
import { IModel } from 'vs/editor/common/editorCommon';
1416
import { IModelService } from 'vs/editor/common/services/modelService';
1517
import { IEventService } from 'vs/platform/event/common/event';
@@ -22,7 +24,8 @@ class EditorInputCache {
2224

2325
private cache: Map.SimpleMap<URI, TPromise<DiffEditorInput>>;
2426

25-
constructor(private replaceService: ReplaceService, private editorService, private modelService: IModelService) {
27+
constructor(private replaceService: ReplaceService, private editorService: IWorkbenchEditorService,
28+
private modelService: IModelService) {
2629
this.cache= new Map.SimpleMap<URI, TPromise<DiffEditorInput>>();
2730
}
2831

@@ -32,10 +35,8 @@ class EditorInputCache {
3235
editorInputPromise= this.createInput(fileMatch);
3336
this.cache.set(fileMatch.resource(), editorInputPromise);
3437
this.refreshInput(fileMatch, text, true);
38+
fileMatch.addListener2('disposed', fileMatch => this.disposeInput(fileMatch));
3539
}
36-
37-
fileMatch.addListener2('disposed', fileMatch => this.disposeInput(fileMatch));
38-
3940
return editorInputPromise;
4041
}
4142

@@ -66,8 +67,7 @@ class EditorInputCache {
6667
let editorInputPromise= this.cache.get(resourceUri);
6768
if (editorInputPromise) {
6869
editorInputPromise.done((diffInput) => {
69-
diffInput.dispose();
70-
this.modelService.destroyModel(this.getReplaceResource(resourceUri));
70+
this.disposeReplaceInput(this.getReplaceResource(resourceUri), diffInput);
7171
this.cache.delete(resourceUri);
7272
});
7373
}
@@ -82,7 +82,8 @@ class EditorInputCache {
8282
return TPromise.join([this.createLeftInput(fileMatch),
8383
this.createRightInput(fileMatch)]).then(inputs => {
8484
const [left, right] = inputs;
85-
return new DiffEditorInput(nls.localize('fileReplaceChanges', "{0} ↔ {1} (after)", fileMatch.name(), fileMatch.name()), undefined, <EditorInput>left, <EditorInput>right);
85+
let editorInput= new DiffEditorInput(nls.localize('fileReplaceChanges', "{0} ↔ {1} (Replace Preview)", fileMatch.name(), fileMatch.name()), undefined, <EditorInput>left, <EditorInput>right);
86+
return editorInput;
8687
});
8788
}
8889

@@ -101,10 +102,14 @@ class EditorInputCache {
101102
});
102103
}
103104

104-
private getReplaceResource(resource: URI): URI {
105-
return resource.with({scheme: 'private'});
105+
private disposeReplaceInput(replaceUri: URI, diffInput: EditorInput):void {
106+
diffInput.dispose();
107+
this.modelService.destroyModel(replaceUri);
106108
}
107109

110+
private getReplaceResource(resource: URI): URI {
111+
return resource.with({scheme: network.Schemas.internal, fragment: 'preview'});
112+
}
108113
}
109114

110115
export class ReplaceService implements IReplaceService {

src/vs/workbench/parts/search/browser/searchViewlet.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import 'vs/css!./media/searchviewlet';
99
import nls = require('vs/nls');
1010
import {TPromise, PPromise} from 'vs/base/common/winjs.base';
11-
import {EditorType, IEditor} from 'vs/editor/common/editorCommon';
11+
import {EditorType, IEditor, IDiffEditorOptions} from 'vs/editor/common/editorCommon';
1212
import lifecycle = require('vs/base/common/lifecycle');
1313
import errors = require('vs/base/common/errors');
1414
import aria = require('vs/base/browser/ui/aria/aria');
@@ -920,7 +920,7 @@ export class SearchViewlet extends Viewlet {
920920

921921
this.telemetryService.publicLog('searchResultChosen');
922922

923-
return this.viewModel.isReplaceActive() ? this.openReplaceEditor(lineMatch, preserveFocus, sideBySide, pinned) : this.open(lineMatch, preserveFocus, sideBySide, pinned);
923+
return this.viewModel.isReplaceActive() ? this.openReplacePreviewEditor(lineMatch, preserveFocus, sideBySide, pinned) : this.open(lineMatch, preserveFocus, sideBySide, pinned);
924924
}
925925

926926
public open(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
@@ -936,10 +936,11 @@ export class SearchViewlet extends Viewlet {
936936
}, sideBySide);
937937
}
938938

939-
private openReplaceEditor(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
939+
private openReplacePreviewEditor(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
940940
return this.replaceService.getInput(element instanceof Match ? element.parent() : element, this.viewModel.replaceText).then((editorInput) => {
941941
this.editorService.openEditor(editorInput, {preserveFocus: preserveFocus, pinned: pinned}).then((editor) => {
942942
let editorControl= (<IEditor>editor.getControl());
943+
editorControl.updateOptions(<IDiffEditorOptions>{originalEditable: true});
943944
if (element instanceof Match) {
944945
editorControl.revealLineInCenter(element.range().startLineNumber);
945946
}

0 commit comments

Comments
 (0)