@@ -895,23 +895,32 @@ export const closeTab = (
895895 } ;
896896} ;
897897
898- type CloseAllOtherTabsAction = {
899- type : WorkspacesActions . CloseAllOtherTabs ;
900- atIndex : number ;
901- } ;
902-
903898export const closeAllOtherTabs = (
904899 atIndex : number
905- ) : WorkspacesThunkAction < Promise < void > , CloseAllOtherTabsAction > => {
900+ ) : WorkspacesThunkAction < Promise < void > , CloseTabsAction | SelectTabAction > => {
906901 return async ( dispatch , getState ) => {
907902 const { tabs } = getState ( ) ;
908- const otherTabs = tabs . filter ( ( _ , index ) => index !== atIndex ) ;
909- for ( const tab of otherTabs ) {
910- if ( ! canCloseTab ( tab ) && ! ( await confirmClosingTabs ( ) ) ) {
911- return ; // Abort the action
912- }
913- }
914- dispatch ( { type : WorkspacesActions . CloseAllOtherTabs , atIndex } ) ;
903+ const tabsToClose = await tabs . reduce (
904+ async ( prev : Promise < WorkspaceTab [ ] > , tab , tabIndex ) => {
905+ const tabsToClose = await prev ;
906+ if ( tabIndex === atIndex ) {
907+ return tabsToClose ; // Skip the tab which is not being closed
908+ }
909+ if ( ! canCloseTab ( tab ) ) {
910+ // Select the closing tab - to show the confirmation dialog in context
911+ dispatch ( { type : WorkspacesActions . SelectTab , atIndex : tabIndex } ) ;
912+ if ( ! ( await confirmClosingTab ( ) ) ) {
913+ return tabsToClose ; // Skip this tab
914+ }
915+ }
916+ return [ ...tabsToClose , tab ] ;
917+ } ,
918+ Promise . resolve ( [ ] )
919+ ) ;
920+ dispatch ( {
921+ type : WorkspacesActions . CloseTabs ,
922+ tabIds : tabsToClose . map ( ( tab ) => tab . id ) ,
923+ } ) ;
915924 cleanupRemovedTabs ( tabs , getState ( ) . tabs ) ;
916925 } ;
917926} ;
0 commit comments