@@ -3766,33 +3766,33 @@ impl Application for App {
37663766 }
37673767 }
37683768 Message :: TabClose ( entity_opt) => {
3769- let mut tasks = Vec :: with_capacity ( 3 ) ;
3769+ let mut tasks = Vec :: with_capacity ( 2 ) ;
37703770
37713771 let entity = entity_opt. unwrap_or_else ( || self . tab_model . active ( ) ) ;
37723772
3773- // Activate closest item
3774- if let Some ( position) = self . tab_model . position ( entity) {
3775- let new_position = if position > 0 {
3776- position - 1
3777- } else {
3778- position + 1
3779- } ;
3773+ // If the last tab is closed, close the window
3774+ // Otherwise, activate closest item
3775+ if self . tab_model . len ( ) == 1 {
3776+ tasks. push ( Task :: future ( async move {
3777+ cosmic:: action:: app ( Message :: WindowClose )
3778+ } ) ) ;
3779+ } else {
3780+ if let Some ( position) = self . tab_model . position ( entity) {
3781+ let new_position = if position > 0 {
3782+ position - 1
3783+ } else {
3784+ position + 1
3785+ } ;
37803786
3781- if let Some ( new_entity) = self . tab_model . entity_at ( new_position) {
3782- tasks. push ( self . update ( Message :: TabActivate ( new_entity) ) ) ;
3787+ if let Some ( new_entity) = self . tab_model . entity_at ( new_position) {
3788+ tasks. push ( self . update ( Message :: TabActivate ( new_entity) ) ) ;
3789+ }
37833790 }
37843791 }
37853792
37863793 // Remove item
37873794 self . tab_model . remove ( entity) ;
37883795
3789- // If that was the last tab, close window
3790- if self . tab_model . iter ( ) . next ( ) . is_none ( ) {
3791- if let Some ( window_id) = self . core . main_window_id ( ) {
3792- tasks. push ( window:: close ( window_id) ) ;
3793- }
3794- }
3795-
37963796 tasks. push ( self . update_watcher ( ) ) ;
37973797
37983798 return Task :: batch ( tasks) ;
0 commit comments