@@ -17,6 +17,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
1717import { IQuickInputService , IQuickPickItem } from 'vs/platform/quickinput/common/quickInput' ;
1818import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
1919import { EditorOptions , IEditor , IEditorInput } from 'vs/workbench/common/editor' ;
20+ import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput' ;
2021import { webviewEditorsExtensionPoint } from 'vs/workbench/contrib/customEditor/browser/extensionPoint' ;
2122import { CustomEditorDiscretion , CustomEditorInfo , CustomEditorSelector , ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor' ;
2223import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput' ;
@@ -109,13 +110,22 @@ export class CustomEditorService implements ICustomEditorService {
109110 return this . promptOpenWith ( resource , options , group ) ;
110111 }
111112
113+ const input = this . createInput ( resource , viewType , group ) ;
114+ return this . openEditorForResource ( resource , input , options , group ) ;
115+ }
116+
117+ public createInput (
118+ resource : URI ,
119+ viewType : string ,
120+ group : IEditorGroup | undefined
121+ ) : CustomFileEditorInput {
112122 const id = generateUuid ( ) ;
113123 const webview = this . webviewService . createWebviewEditorOverlay ( id , { } , { } ) ;
114124 const input = this . instantiationService . createInstance ( CustomFileEditorInput , resource , viewType , id , new UnownedDisposable ( webview ) ) ;
115125 if ( group ) {
116126 input . updateGroup ( group ! . id ) ;
117127 }
118- return this . openEditorForResource ( resource , input , options , group ) ;
128+ return input ;
119129 }
120130
121131 private async openEditorForResource (
@@ -159,6 +169,34 @@ export class CustomEditorContribution implements IWorkbenchContribution {
159169 return ;
160170 }
161171
172+ if ( editor instanceof DiffEditorInput ) {
173+ if ( editor . modifiedInput instanceof CustomFileEditorInput ) {
174+ return ;
175+ }
176+ const resource = editor . modifiedInput . getResource ( ) ;
177+ if ( ! resource ) {
178+ return ;
179+ }
180+
181+ const customEditors = distinct ( [
182+ ...this . customEditorService . getUserConfiguredCustomEditors ( resource ) ,
183+ ...this . customEditorService . getContributedCustomEditors ( resource ) ,
184+ ] , editor => editor . id ) ;
185+
186+ // Always prefer the first editor in the diff editor case
187+ if ( customEditors . length > 0 ) {
188+ return {
189+ override : ( async ( ) => {
190+ const newModified = this . customEditorService . createInput ( resource , customEditors [ 0 ] . id , group ) ;
191+ const input = new DiffEditorInput ( editor . getName ( ) , editor . getDescription ( ) , editor . originalInput , newModified ) ;
192+ return this . editorService . openEditor ( input , { ...options , ignoreOverrides : true } , group ) ;
193+ } ) ( ) ,
194+ } ;
195+ }
196+
197+ return undefined ;
198+ }
199+
162200 const resource = editor . getResource ( ) ;
163201 if ( ! resource ) {
164202 return ;
0 commit comments