@@ -615,8 +615,13 @@ export class HistoryService extends Disposable implements IHistoryService {
615615 private static readonly MAX_RECENTLY_CLOSED_EDITORS = 20 ;
616616
617617 private recentlyClosedEditors : IRecentlyClosedEditor [ ] = [ ] ;
618+ private ignoreEditorCloseEvent = false ;
618619
619620 private onEditorClosed ( event : IEditorCloseEvent ) : void {
621+ if ( this . ignoreEditorCloseEvent ) {
622+ return ; // blocked
623+ }
624+
620625 const { editor, replaced } = event ;
621626 if ( replaced ) {
622627 return ; // ignore if editor was replaced
@@ -695,7 +700,17 @@ export class HistoryService extends Disposable implements IHistoryService {
695700 const restoredEditor = this . editorInputFactory . getEditorInputFactory ( lastClosedEditor . serialized . typeId ) ?. deserialize ( this . instantiationService , lastClosedEditor . serialized . value ) ;
696701 let editorPane : IEditorPane | undefined = undefined ;
697702 if ( restoredEditor && ! this . editorGroupService . activeGroup . isOpened ( restoredEditor ) ) {
698- editorPane = await this . editorService . openEditor ( restoredEditor , options ) ;
703+ // Fix for https://github.com/microsoft/vscode/issues/107850
704+ // If opening an editor fails, it is possible that we get
705+ // another editor-close event as a result. But we really do
706+ // want to ignore that in our list of recently closed editors
707+ // to prevent endless loops.
708+ this . ignoreEditorCloseEvent = true ;
709+ try {
710+ editorPane = await this . editorService . openEditor ( restoredEditor , options ) ;
711+ } finally {
712+ this . ignoreEditorCloseEvent = false ;
713+ }
699714 }
700715
701716 // If no editor was opened, try with the next one
@@ -705,6 +720,8 @@ export class HistoryService extends Disposable implements IHistoryService {
705720 // but make sure to remove this one from the list to prevent
706721 // endless loops.
707722 remove ( this . recentlyClosedEditors , lastClosedEditor ) ;
723+
724+ // Try with next one
708725 this . reopenLastClosedEditor ( ) ;
709726 }
710727 }
0 commit comments