@@ -128,17 +128,31 @@ impl Window {
128
128
pub fn remove_by_idx ( & mut self , idx : usize ) -> Rc < Tab > {
129
129
self . invalidate ( ) ;
130
130
let active = self . get_active ( ) . map ( Rc :: clone) ;
131
- let tab = self . tabs . remove ( idx) ;
132
- self . fixup_active_tab_after_removal ( active) ;
133
- tab
131
+ self . do_remove_idx ( idx, active)
134
132
}
135
133
136
134
pub fn remove_by_id ( & mut self , id : TabId ) {
137
135
let active = self . get_active ( ) . map ( Rc :: clone) ;
138
136
if let Some ( idx) = self . idx_by_id ( id) {
139
- self . tabs . remove ( idx) ;
137
+ self . do_remove_idx ( idx, active) ;
138
+ }
139
+ }
140
+
141
+ fn do_remove_idx ( & mut self , idx : usize , active : Option < Rc < Tab > > ) -> Rc < Tab > {
142
+ if let ( Some ( active) , Some ( removing) ) = ( & active, self . tabs . get ( idx) ) {
143
+ if active. tab_id ( ) == removing. tab_id ( )
144
+ && config:: configuration ( ) . switch_to_last_active_tab_when_closing_tab
145
+ {
146
+ // If we are removing the active tab, switch back to
147
+ // the previously active tab
148
+ if let Some ( last_active) = self . get_last_active_idx ( ) {
149
+ self . set_active_without_saving ( last_active) ;
150
+ }
151
+ }
140
152
}
153
+ let tab = self . tabs . remove ( idx) ;
141
154
self . fixup_active_tab_after_removal ( active) ;
155
+ tab
142
156
}
143
157
144
158
pub fn get_active ( & self ) -> Option < & Rc < Tab > > {
0 commit comments