44 *--------------------------------------------------------------------------------------------*/
55
66import { coalesce } from 'vs/base/common/arrays' ;
7+ import { Emitter } from 'vs/base/common/event' ;
78import { Lazy } from 'vs/base/common/lazy' ;
89import { Disposable } from 'vs/base/common/lifecycle' ;
910import { basename , isEqual } from 'vs/base/common/resources' ;
@@ -15,9 +16,11 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
1516import { IEditorOptions , ITextEditorOptions } from 'vs/platform/editor/common/editor' ;
1617import { FileOperation , IFileService } from 'vs/platform/files/common/files' ;
1718import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
19+ import { ILabelService } from 'vs/platform/label/common/label' ;
1820import { IQuickInputService , IQuickPickItem } from 'vs/platform/quickinput/common/quickInput' ;
1921import * as colorRegistry from 'vs/platform/theme/common/colorRegistry' ;
2022import { registerThemingParticipant } from 'vs/platform/theme/common/themeService' ;
23+ import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor' ;
2124import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
2225import { EditorInput , EditorOptions , IEditor , IEditorInput } from 'vs/workbench/common/editor' ;
2326import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput' ;
@@ -30,8 +33,6 @@ import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor
3033import { IEditorService , IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService' ;
3134import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService' ;
3235import { CustomFileEditorInput } from './customEditorInput' ;
33- import { Emitter } from 'vs/base/common/event' ;
34- import { ILabelService } from 'vs/platform/label/common/label' ;
3536
3637export const defaultEditorId = 'default' ;
3738
@@ -314,12 +315,26 @@ export const customEditorsAssociationsKey = 'workbench.experimental.editorAssoci
314315
315316export type CustomEditorsAssociations = readonly ( CustomEditorSelector & { readonly viewType : string ; } ) [ ] ;
316317
317- export class CustomEditorContribution implements IWorkbenchContribution {
318+ export class CustomEditorContribution extends Disposable implements IWorkbenchContribution {
318319 constructor (
319- @IEditorService private readonly editorService : IEditorService ,
320+ @IEditorService private readonly editorService : EditorServiceImpl ,
320321 @ICustomEditorService private readonly customEditorService : ICustomEditorService ,
321322 ) {
322- this . editorService . overrideOpenEditor ( ( editor , options , group ) => this . onEditorOpening ( editor , options , group ) ) ;
323+ super ( ) ;
324+
325+ this . _register ( this . editorService . overrideOpenEditor ( ( editor , options , group ) => {
326+ return this . onEditorOpening ( editor , options , group ) ;
327+ } ) ) ;
328+
329+ this . _register ( this . editorService . onDidCloseEditor ( ( { editor } ) => {
330+ if ( ! ( editor instanceof CustomFileEditorInput ) ) {
331+ return ;
332+ }
333+
334+ if ( ! this . editorService . editors . some ( other => other === editor ) ) {
335+ editor . dispose ( ) ;
336+ }
337+ } ) ) ;
323338 }
324339
325340 private onEditorOpening (
@@ -329,7 +344,15 @@ export class CustomEditorContribution implements IWorkbenchContribution {
329344 ) : IOpenEditorOverride | undefined {
330345 if ( editor instanceof CustomFileEditorInput ) {
331346 if ( editor . group === group . id ) {
347+ // No need to do anything
332348 return undefined ;
349+ } else {
350+ // Create a copy of the input.
351+ // Unlike normal editor inputs, we do not want to share custom editor inputs
352+ // between multiple editors / groups.
353+ return {
354+ override : this . customEditorService . openWith ( editor . getResource ( ) , editor . viewType , options , group )
355+ } ;
333356 }
334357 }
335358
0 commit comments