Skip to content

Commit 7d4b824

Browse files
committed
add switch_to_last_active_tab_when_closing_tab config option
refs: #2487
1 parent 3583ccf commit 7d4b824

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

config/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ pub struct Config {
9494
/// The color palette
9595
pub colors: Option<Palette>,
9696

97+
#[dynamic(default)]
98+
pub switch_to_last_active_tab_when_closing_tab: bool,
99+
97100
#[dynamic(default)]
98101
pub window_frame: WindowFrameConfig,
99102

mux/src/window.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,31 @@ impl Window {
128128
pub fn remove_by_idx(&mut self, idx: usize) -> Rc<Tab> {
129129
self.invalidate();
130130
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)
134132
}
135133

136134
pub fn remove_by_id(&mut self, id: TabId) {
137135
let active = self.get_active().map(Rc::clone);
138136
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+
}
140152
}
153+
let tab = self.tabs.remove(idx);
141154
self.fixup_active_tab_after_removal(active);
155+
tab
142156
}
143157

144158
pub fn get_active(&self) -> Option<&Rc<Tab>> {

0 commit comments

Comments
 (0)