@@ -333,7 +333,7 @@ export class ServerManagerView {
333333 }
334334
335335 // Open last active tab
336- const firstTab = this . tabs [ 0 ] ;
336+ const firstTab = this . getTabByOrder ( this . tabs , 0 ) ! ;
337337 let lastActiveTabId = ConfigUtil . getConfigItem (
338338 "lastActiveTabId" ,
339339 firstTab . properties . tabId ,
@@ -343,22 +343,22 @@ export class ServerManagerView {
343343 // It will be undefined if user disconnected the server for lastActiveTab.
344344 if (
345345 lastActiveTab === undefined ||
346- lastActiveTab . properties . index >= servers . length
346+ lastActiveTab . properties . order >= servers . length
347347 ) {
348348 lastActiveTabId = firstTab . properties . tabId ;
349349 }
350350
351351 // `webview.load()` for lastActiveTabId before the others
352352 await this . activateTab ( lastActiveTabId ) ;
353353 await Promise . all (
354- servers . map ( async ( server , i ) => {
354+ servers . map ( async ( server ) => {
355355 // After the lastActiveTabId is activated, we load the others in the background
356356 // without activating them, to prevent flashing of server icons
357357 if ( server . id === lastActiveTabId ) {
358358 return ;
359359 }
360360
361- const tab = this . tabs [ i ] ;
361+ const tab = this . getTabById ( server . id ) ;
362362 if ( tab instanceof ServerTab ) ( await tab . webview ) . load ( ) ;
363363 } ) ,
364364 ) ;
@@ -372,15 +372,15 @@ export class ServerManagerView {
372372 }
373373 }
374374
375- initServer ( server : ServerConfig , index : number ) : ServerTab {
375+ initServer ( server : ServerConfig , order : number ) : ServerTab {
376376 const tabId = server . id ;
377377 const tab : ServerTab = new ServerTab ( {
378378 role : "server" ,
379379 icon : DomainUtil . iconAsUrl ( server . icon ) ,
380380 label : server . alias ,
381381 $root : this . $tabsContainer ,
382382 onClick : this . activateLastTab . bind ( this , tabId ) ,
383- index ,
383+ order ,
384384 tabId,
385385 onHover : this . onHover . bind ( this , tabId ) ,
386386 onHoverOut : this . onHoverOut . bind ( this , tabId ) ,
@@ -560,7 +560,7 @@ export class ServerManagerView {
560560 return ;
561561 }
562562
563- const index = this . tabs . length ;
563+ const order = this . tabs . length ;
564564 const tabId = this . generateTabId ( ) ;
565565 this . functionalTabs . set ( tabProperties . page , tabId ) ;
566566 const $view = await tabProperties . makeView ( ) ;
@@ -573,7 +573,7 @@ export class ServerManagerView {
573573 label : tabProperties . label ,
574574 page : tabProperties . page ,
575575 $root : this . $tabsContainer ,
576- index ,
576+ order ,
577577 tabId,
578578 onClick : this . activateTab . bind ( this , tabId ) ,
579579 onDestroy : async ( ) => {
@@ -656,11 +656,18 @@ export class ServerManagerView {
656656 role : tab . properties . role ,
657657 page : tab . properties . page ,
658658 label : tab . properties . label ,
659- index : tab . properties . index ,
659+ order : tab . properties . order ,
660660 id : tab . properties . tabId ,
661661 } ) ) ;
662662 }
663663
664+ getTabByOrder (
665+ tabs : ServerOrFunctionalTab [ ] ,
666+ order : number ,
667+ ) : ServerOrFunctionalTab | undefined {
668+ return tabs . find ( ( tab ) => tab . properties . order === order ) ;
669+ }
670+
664671 async activateTab ( id : string , hideOldTab = true ) : Promise < void > {
665672 const tab = this . getTabById ( id ) ;
666673 if ( ! tab ) {
@@ -735,7 +742,10 @@ export class ServerManagerView {
735742
736743 // Issue #188: If the functional tab was not focused, do not activate another tab.
737744 if ( this . activeTabId === tabId ) {
738- await this . activateTab ( this . tabs [ 0 ] . properties . tabId , false ) ;
745+ await this . activateTab (
746+ this . getTabByOrder ( this . tabs , 0 ) ! . properties . tabId ,
747+ false ,
748+ ) ;
739749 }
740750 }
741751
0 commit comments