@@ -845,13 +845,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
845845 }
846846
847847 getViewDescriptors ( container : ViewContainer ) : ViewDescriptorCollection {
848- let viewDescriptorCollectionItem = this . viewDescriptorCollections . get ( container ) ;
849- if ( ! viewDescriptorCollectionItem ) {
850- // Create and register the collection if does not exist
851- this . onDidRegisterViewContainer ( container ) ;
852- viewDescriptorCollectionItem = this . viewDescriptorCollections . get ( container ) ;
853- }
854- return viewDescriptorCollectionItem ! . viewDescriptorCollection ;
848+ return this . getOrRegisterViewDescriptorCollection ( container ) ;
855849 }
856850
857851 moveViews ( views : IViewDescriptor [ ] , viewContainer : ViewContainer ) : void {
@@ -942,18 +936,28 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
942936 }
943937
944938 private onDidRegisterViewContainer ( viewContainer : ViewContainer ) : void {
945- const disposables = new DisposableStore ( ) ;
946- const viewDescriptorCollection = disposables . add ( new ViewDescriptorCollection ( this . contextKeyService ) ) ;
939+ this . getOrRegisterViewDescriptorCollection ( viewContainer ) ;
940+ }
947941
948- this . onDidChangeActiveViews ( { added : viewDescriptorCollection . activeViewDescriptors , removed : [ ] } ) ;
949- viewDescriptorCollection . onDidChangeActiveViews ( changed => this . onDidChangeActiveViews ( changed ) , this , disposables ) ;
942+ private getOrRegisterViewDescriptorCollection ( viewContainer : ViewContainer ) : ViewDescriptorCollection {
943+ let viewDescriptorCollection = this . viewDescriptorCollections . get ( viewContainer ) ?. viewDescriptorCollection ;
944+
945+ if ( ! viewDescriptorCollection ) {
946+ const disposables = new DisposableStore ( ) ;
947+ viewDescriptorCollection = disposables . add ( new ViewDescriptorCollection ( this . contextKeyService ) ) ;
950948
951- this . viewDescriptorCollections . set ( viewContainer , { viewDescriptorCollection, disposable : disposables } ) ;
949+ this . onDidChangeActiveViews ( { added : viewDescriptorCollection . activeViewDescriptors , removed : [ ] } ) ;
950+ viewDescriptorCollection . onDidChangeActiveViews ( changed => this . onDidChangeActiveViews ( changed ) , this , disposables ) ;
952951
953- const viewsToRegister = this . getViewsByContainer ( viewContainer ) ;
954- if ( viewsToRegister . length ) {
955- this . addViews ( viewContainer , viewsToRegister ) ;
952+ this . viewDescriptorCollections . set ( viewContainer , { viewDescriptorCollection, disposable : disposables } ) ;
953+
954+ const viewsToRegister = this . getViewsByContainer ( viewContainer ) ;
955+ if ( viewsToRegister . length ) {
956+ this . addViews ( viewContainer , viewsToRegister ) ;
957+ }
956958 }
959+
960+ return viewDescriptorCollection ;
957961 }
958962
959963 private onDidDeregisterViewContainer ( viewContainer : ViewContainer ) : void {
0 commit comments