Skip to content

Commit

Permalink
add switch_to_last_active_tab_when_closing_tab config option
Browse files Browse the repository at this point in the history
refs: #2487
  • Loading branch information
wez committed Sep 5, 2022
1 parent 3583ccf commit 7d4b824
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ pub struct Config {
/// The color palette
pub colors: Option<Palette>,

#[dynamic(default)]
pub switch_to_last_active_tab_when_closing_tab: bool,

#[dynamic(default)]
pub window_frame: WindowFrameConfig,

Expand Down
22 changes: 18 additions & 4 deletions mux/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,31 @@ impl Window {
pub fn remove_by_idx(&mut self, idx: usize) -> Rc<Tab> {
self.invalidate();
let active = self.get_active().map(Rc::clone);
let tab = self.tabs.remove(idx);
self.fixup_active_tab_after_removal(active);
tab
self.do_remove_idx(idx, active)
}

pub fn remove_by_id(&mut self, id: TabId) {
let active = self.get_active().map(Rc::clone);
if let Some(idx) = self.idx_by_id(id) {
self.tabs.remove(idx);
self.do_remove_idx(idx, active);
}
}

fn do_remove_idx(&mut self, idx: usize, active: Option<Rc<Tab>>) -> Rc<Tab> {
if let (Some(active), Some(removing)) = (&active, self.tabs.get(idx)) {
if active.tab_id() == removing.tab_id()
&& config::configuration().switch_to_last_active_tab_when_closing_tab
{
// If we are removing the active tab, switch back to
// the previously active tab
if let Some(last_active) = self.get_last_active_idx() {
self.set_active_without_saving(last_active);
}
}
}
let tab = self.tabs.remove(idx);
self.fixup_active_tab_after_removal(active);
tab
}

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

0 comments on commit 7d4b824

Please sign in to comment.