This commit is contained in:
Kovid Goyal 2026-03-04 13:46:12 +05:30
parent d15905c918
commit 0170c2c0c6
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -1479,6 +1479,10 @@ def new_tab(
def remove(self, removed_tab: Tab) -> None:
active_tab_before_removal = self.active_tab
tabs = tuple(self.tabs_to_be_shown_in_tab_bar)
try:
idx_before_removal = tabs.index(active_tab_before_removal)
except Exception:
idx_before_removal = -1
remove_tab(self.os_window_id, removed_tab.id)
self.tabs.remove(removed_tab)
while True:
@ -1529,7 +1533,10 @@ def previous_active_tab() -> Tab | None:
next_active_tab = tabs[-1]
remove_from_end_of_active_history(next_active_tab)
if next_active_tab not in self.tabs:
next_active_tab = self.tabs[max(0, min(self.active_tab_idx, len(self.tabs) - 1))]
if idx_before_removal > -1 and (left_tabs := tuple(t for t in tabs if t is not removed_tab)):
next_active_tab = left_tabs[max(0, min(idx_before_removal, len(left_tabs) - 1))]
else:
next_active_tab = self.tabs[max(0, min(self.active_tab_idx, len(self.tabs) - 1))]
self._set_active_tab(self.tabs.index(next_active_tab), store_in_history=False)
else:
if len(self.tabs):