@@ -459,18 +459,39 @@ const restore_tab_groups = async (
459459 return
460460 }
461461
462- await vscode . commands . executeCommand ( 'workbench.action.closeAllEditors' )
463-
464- for ( const editor of saved_state . editors ) {
465- try {
466- const uri = vscode . Uri . parse ( editor . uri )
467- await vscode . window . showTextDocument ( uri , {
468- viewColumn : editor . view_column ,
469- preview : false ,
470- preserveFocus : ! editor . is_active
471- } )
472- } catch ( error ) {
473- console . error ( `Failed to restore editor for ${ editor . uri } :` , error )
462+ if ( current_editors . length > saved_state . editors . length ) {
463+ const tabs_to_close : vscode . Tab [ ] = [ ]
464+ for ( const tab_group of vscode . window . tabGroups . all ) {
465+ for ( const tab of tab_group . tabs ) {
466+ if ( tab . input instanceof vscode . TabInputText ) {
467+ const uri = tab . input . uri . toString ( )
468+ const is_saved = saved_state . editors . some (
469+ ( saved ) =>
470+ saved . uri == uri && saved . view_column == tab_group . viewColumn
471+ )
472+ if ( ! is_saved ) {
473+ tabs_to_close . push ( tab )
474+ }
475+ }
476+ }
477+ }
478+ if ( tabs_to_close . length > 0 ) {
479+ await vscode . window . tabGroups . close ( tabs_to_close )
480+ }
481+ } else {
482+ await vscode . commands . executeCommand ( 'workbench.action.closeAllEditors' )
483+
484+ for ( const editor of saved_state . editors ) {
485+ try {
486+ const uri = vscode . Uri . parse ( editor . uri )
487+ await vscode . window . showTextDocument ( uri , {
488+ viewColumn : editor . view_column ,
489+ preview : false ,
490+ preserveFocus : ! editor . is_active
491+ } )
492+ } catch ( error ) {
493+ console . error ( `Failed to restore editor for ${ editor . uri } :` , error )
494+ }
474495 }
475496 }
476497
0 commit comments