@@ -472,12 +472,16 @@ const reducer: Reducer<WorkspacesState, Action> = (
472472 }
473473
474474 if ( isAction < CloseTabsAction > ( action , WorkspacesActions . CloseTabs ) ) {
475- return _bulkTabsClose ( {
475+ const newState = _bulkTabsClose ( {
476476 state,
477477 isToBeClosed : ( tab ) => {
478478 return action . tabIds . includes ( tab . id ) ;
479479 } ,
480480 } ) ;
481+ // Add the updated active tab if needed
482+ return action . activeTabId
483+ ? { ...newState , activeTabId : action . activeTabId }
484+ : newState ;
481485 }
482486
483487 if (
@@ -881,7 +885,11 @@ async function confirmClosingTab() {
881885 } ) ;
882886}
883887
884- type CloseTabsAction = { type : WorkspacesActions . CloseTabs ; tabIds : string [ ] } ;
888+ type CloseTabsAction = {
889+ type : WorkspacesActions . CloseTabs ;
890+ tabIds : string [ ] ;
891+ activeTabId ?: string ;
892+ } ;
885893
886894export const closeTab = (
887895 atIndex : number
@@ -901,26 +909,25 @@ export const closeAllOtherTabs = (
901909) : WorkspacesThunkAction < Promise < void > , CloseTabsAction | SelectTabAction > => {
902910 return async ( dispatch , getState ) => {
903911 const { tabs } = getState ( ) ;
904- const tabsToClose = await tabs . reduce (
905- async ( prev : Promise < WorkspaceTab [ ] > , tab , tabIndex ) => {
906- const tabsToClose = await prev ;
907- if ( tabIndex === atIndex ) {
908- return tabsToClose ; // Skip the tab which is not being closed
909- }
910- if ( ! canCloseTab ( tab ) ) {
911- // Select the closing tab - to show the confirmation dialog in context
912- dispatch ( { type : WorkspacesActions . SelectTab , atIndex : tabIndex } ) ;
913- if ( ! ( await confirmClosingTab ( ) ) ) {
914- return tabsToClose ; // Skip this tab
915- }
912+ const remainingTab = tabs [ atIndex ] ;
913+ const tabsToClose = [ ] ;
914+ for ( const [ tabIndex , tab ] of tabs . entries ( ) ) {
915+ if ( tabIndex === atIndex ) {
916+ continue ; // Skip the tab which is not being closed
917+ }
918+ if ( ! canCloseTab ( tab ) ) {
919+ // Select the closing tab - to show the confirmation dialog in context
920+ dispatch ( { type : WorkspacesActions . SelectTab , atIndex : tabIndex } ) ;
921+ if ( ! ( await confirmClosingTab ( ) ) ) {
922+ continue ; // Skip this tab
916923 }
917- return [ ...tabsToClose , tab ] ;
918- } ,
919- Promise . resolve ( [ ] )
920- ) ;
924+ }
925+ tabsToClose . push ( tab ) ;
926+ }
921927 dispatch ( {
922928 type : WorkspacesActions . CloseTabs ,
923929 tabIds : tabsToClose . map ( ( tab ) => tab . id ) ,
930+ activeTabId : remainingTab . id ,
924931 } ) ;
925932 cleanupRemovedTabs ( tabs , getState ( ) . tabs ) ;
926933 } ;
0 commit comments