44 *--------------------------------------------------------------------------------------------*/
55'use strict' ;
66
7+ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
8+ import { IEditorOptions , ITextEditorOptions } from 'vs/platform/editor/common/editor' ;
9+ import { localize } from 'vs/nls' ;
710import { disposed } from 'vs/base/common/errors' ;
811import { IDisposable , dispose } from 'vs/base/common/lifecycle' ;
912import { equals as objectEquals } from 'vs/base/common/objects' ;
@@ -15,7 +18,8 @@ import { IRange } from 'vs/editor/common/core/range';
1518import { ISelection } from 'vs/editor/common/core/selection' ;
1619import { IDecorationOptions , IDecorationRenderOptions , ILineChange } from 'vs/editor/common/editorCommon' ;
1720import { ISingleEditOperation } from 'vs/editor/common/model' ;
18- import { ITextEditorOptions , Position as EditorPosition } from 'vs/platform/editor/common/editor' ;
21+ import { EditorPosition } from 'vs/workbench/api/shared/editor' ;
22+ import { CommandsRegistry } from 'vs/platform/commands/common/commands' ;
1923import { IApplyEditsOptions , ITextEditorConfigurationUpdate , IUndoStopOptions , TextEditorRevealType , WorkspaceEditDto , reviveWorkspaceEditDto } from 'vs/workbench/api/node/extHost.protocol' ;
2024import { IEditorService , SIDE_GROUP , ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService' ;
2125import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService' ;
@@ -127,7 +131,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
127131 } ) ;
128132 }
129133
130- $tryShowEditor ( id : string , position : EditorPosition ) : TPromise < void > {
134+ $tryShowEditor ( id : string , position ? : EditorPosition ) : TPromise < void > {
131135 let mainThreadEditor = this . _documentsAndEditors . getEditor ( id ) ;
132136 if ( mainThreadEditor ) {
133137 let model = mainThreadEditor . getModel ( ) ;
@@ -241,6 +245,36 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
241245 }
242246}
243247
248+ // --- commands
249+
250+ CommandsRegistry . registerCommand ( '_workbench.open' , function ( accessor : ServicesAccessor , args : [ URI , IEditorOptions , EditorPosition ] ) {
251+ const editorService = accessor . get ( IEditorService ) ;
252+ const editorGroupService = accessor . get ( IEditorGroupsService ) ;
253+
254+ const [ resource , options , position ] = args ;
255+
256+ return editorService . openEditor ( { resource, options } , findEditorGroup ( editorGroupService , position ) ) . then ( ( ) => void 0 ) ;
257+ } ) ;
258+
259+ CommandsRegistry . registerCommand ( '_workbench.diff' , function ( accessor : ServicesAccessor , args : [ URI , URI , string , string , IEditorOptions , EditorPosition ] ) {
260+ const editorService = accessor . get ( IEditorService ) ;
261+ const editorGroupService = accessor . get ( IEditorGroupsService ) ;
262+
263+ let [ leftResource , rightResource , label , description , options , position ] = args ;
264+
265+ if ( ! options || typeof options !== 'object' ) {
266+ options = {
267+ preserveFocus : false
268+ } ;
269+ }
270+
271+ if ( ! label ) {
272+ label = localize ( 'diffLeftRightLabel' , "{0} ⟷ {1}" , leftResource . toString ( true ) , rightResource . toString ( true ) ) ;
273+ }
274+
275+ return editorService . openEditor ( { leftResource, rightResource, label, description, options } , findEditorGroup ( editorGroupService , position ) ) . then ( ( ) => void 0 ) ;
276+ } ) ;
277+
244278export function findEditorGroup ( editorGroupService : IEditorGroupsService , position ?: EditorPosition ) : GroupIdentifier {
245279 if ( typeof position !== 'number' ) {
246280 return ACTIVE_GROUP ; // prefer active group when position is undefined
0 commit comments