mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 13:52:55 +03:00
fix window vanishing when a tab is closed
We weren't fixing up the active tab position correctly after removing a tab. I think this bug crept in around the ActivateLastTab changes. We now try harder to set active idx back to the tab that was active prior to the remove, and ensure that we set the active index to something within range if it was the active tab that was removed. Refs: https://github.com/wez/wezterm/issues/690
This commit is contained in:
parent
776aedf97e
commit
adbe545d44
@ -24,6 +24,7 @@ As features stabilize some brief notes about them will accumulate here.
|
||||
* Improved font IO performance and memory usage on all platforms
|
||||
* New [window:toast_notification](config/lua/window/toast_notification.md) method for showing desktop notifications. [#619](https://github.com/wez/wezterm/issues/619)
|
||||
* Fixed: half-pixel gaps in ligatured/double-wide glyphs depending on the font size [#614](https://github.com/wez/wezterm/issues/614)
|
||||
* Fixed: Window could vanish if a tab closed while the rightmost tab was active(!) [#690](https://github.com/wez/wezterm/issues/690)
|
||||
|
||||
### 20210405-110924-a5bb5be8
|
||||
|
||||
|
@ -451,6 +451,7 @@ impl Mux {
|
||||
}
|
||||
|
||||
for window_id in dead_windows {
|
||||
log::trace!("window {} is dead", window_id);
|
||||
self.remove_window_internal(window_id);
|
||||
}
|
||||
}
|
||||
|
@ -93,18 +93,35 @@ impl Window {
|
||||
None
|
||||
}
|
||||
|
||||
fn fixup_active_tab_after_removal(&mut self, active: Option<Rc<Tab>>) {
|
||||
let len = self.tabs.len();
|
||||
if let Some(active) = active {
|
||||
for (idx, tab) in self.tabs.iter().enumerate() {
|
||||
if tab.tab_id() == active.tab_id() {
|
||||
self.set_active_without_saving(idx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len > 0 && self.active >= len {
|
||||
self.set_active_without_saving(len - 1);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_by_idx(&mut self, idx: usize) -> Rc<Tab> {
|
||||
self.invalidated = true;
|
||||
self.tabs.remove(idx)
|
||||
let active = self.get_active().map(Rc::clone);
|
||||
let tab = self.tabs.remove(idx);
|
||||
self.fixup_active_tab_after_removal(active);
|
||||
tab
|
||||
}
|
||||
|
||||
pub fn remove_by_id(&mut self, id: TabId) -> bool {
|
||||
if let Some(idx) = self.idx_by_id(id) {
|
||||
let active = self.get_active().map(Rc::clone);
|
||||
self.tabs.remove(idx);
|
||||
let len = self.tabs.len();
|
||||
if len > 0 && self.active == idx && idx >= len {
|
||||
self.set_active_without_saving(len - 1);
|
||||
}
|
||||
self.fixup_active_tab_after_removal(active);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@ -172,13 +189,15 @@ impl Window {
|
||||
invalidated = true;
|
||||
}
|
||||
if tab.is_dead() {
|
||||
return Some(tab.tab_id());
|
||||
Some(tab.tab_id())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
for tab_id in dead {
|
||||
log::trace!("Window::prune_dead_tabs: tab_id {} is dead", tab_id);
|
||||
self.remove_by_id(tab_id);
|
||||
invalidated = true;
|
||||
}
|
||||
@ -199,6 +218,7 @@ impl Window {
|
||||
})
|
||||
.collect();
|
||||
for tab_id in dead {
|
||||
log::trace!("Window::prune_dead_tabs: (live) tab_id {} is dead", tab_id);
|
||||
self.remove_by_id(tab_id);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user