@@ -176,13 +176,15 @@ class EmptyEditorGroup implements IEditorGroup, IEditorGroupView {
176176export const fakeActiveGroup = new EmptyEditorGroup ( )
177177
178178class SimpleEditorPane implements IEditorPane {
179- constructor ( private editor ?: ICodeEditor ) { }
179+ constructor (
180+ public input : EditorInput | undefined ,
181+ private editor ?: ICodeEditor
182+ ) { }
180183
181184 onDidChangeControl = Event . None
182185 onDidChangeSizeConstraints = Event . None
183186 onDidFocus = Event . None
184187 onDidBlur = Event . None
185- input = undefined
186188 options = undefined
187189 group = fakeActiveGroup
188190 scopedContextKeyService = undefined
@@ -311,7 +313,7 @@ export function wrapOpenEditor(
311313 }
312314
313315 // Return a very simple editor pane, only the `getControl` method is used
314- return new SimpleEditorPane ( modelEditor )
316+ return new SimpleEditorPane ( isEditorInput ( editor ) ? editor : undefined , modelEditor )
315317 }
316318
317319 return openEditor
@@ -414,7 +416,7 @@ export class MonacoEditorService extends EditorService {
414416
415417class StandaloneEditorPane implements IVisibleEditorPane {
416418 constructor (
417- public readonly editor : IStandaloneCodeEditor ,
419+ public readonly editor : ICodeEditor ,
418420 public input : TextResourceEditorInput ,
419421 public group : IEditorGroup
420422 ) { }
@@ -466,8 +468,11 @@ class StandaloneEditorGroup extends Disposable implements IEditorGroup, IEditorG
466468 public active : boolean = false
467469 constructor (
468470 public editor : IStandaloneCodeEditor ,
471+ private openEditorFallback : OpenEditor | undefined ,
469472 @IInstantiationService instantiationService : IInstantiationService ,
470- @IContextKeyService public scopedContextKeyService : IContextKeyService
473+ @IContextKeyService public scopedContextKeyService : IContextKeyService ,
474+ @IEditorService public editorService : IEditorService ,
475+ @ITextModelService private textModelService : ITextModelService
471476 ) {
472477 super ( )
473478 const onNewModel = ( uri : URI ) => {
@@ -656,17 +661,31 @@ class StandaloneEditorGroup extends Disposable implements IEditorGroup, IEditorG
656661 getIndexOfEditor = ( editorInput : EditorInput ) =>
657662 this . pane != null && this . pane . input === editorInput ? 0 : - 1
658663
659- openEditor = async ( editor : EditorInput ) : Promise < IEditorPane | undefined > => {
664+ openEditor = async (
665+ editor : EditorInput ,
666+ options ?: IEditorOptions
667+ ) : Promise < IEditorPane | undefined > => {
660668 if ( editor . isDisposed ( ) ) {
661669 return undefined
662670 }
663671
664- if (
665- editor instanceof TextResourceEditorInput &&
666- editor . resource . toString ( ) === this . pane ?. input . resource . toString ( )
667- ) {
668- this . focus ( )
669- return this . pane
672+ if ( editor instanceof TextResourceEditorInput ) {
673+ if ( editor . resource . toString ( ) === this . pane ?. input . resource . toString ( ) ) {
674+ this . focus ( )
675+ return this . pane
676+ }
677+
678+ if ( this . openEditorFallback != null ) {
679+ const modelRef = await this . textModelService . createModelReference ( editor . resource )
680+ const modelEditor = await this . openEditorFallback ( modelRef , options , false )
681+ if ( modelEditor == null ) {
682+ // Dispose the newly created model if `openEditor` wasn't able to open it
683+ modelRef . dispose ( )
684+ return undefined
685+ }
686+
687+ return new SimpleEditorPane ( editor , modelEditor )
688+ }
670689 }
671690 return undefined
672691 }
@@ -718,6 +737,7 @@ export class MonacoDelegateEditorGroupsService<D extends IEditorGroupsService>
718737 constructor (
719738 protected delegate : D ,
720739 emptyDelegate : boolean ,
740+ private openEditorFallback : OpenEditor | undefined ,
721741 @IInstantiationService private instantiationService : IInstantiationService
722742 ) {
723743 super ( )
@@ -771,7 +791,11 @@ export class MonacoDelegateEditorGroupsService<D extends IEditorGroupsService>
771791 onEditorFocused ( )
772792 }
773793
774- const newGroup = instantiationService . createInstance ( StandaloneEditorGroup , editor )
794+ const newGroup = instantiationService . createInstance (
795+ StandaloneEditorGroup ,
796+ editor ,
797+ this . openEditorFallback
798+ )
775799 this . additionalGroups . push ( newGroup )
776800 this . _onDidAddGroup . fire ( newGroup )
777801 }
0 commit comments