diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index a96c909a5..52c96f795 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -464,9 +464,11 @@ class TabbedBrowser(QWidget): return False opened = self._opened_tab() - self._opened_tab = None # Clear state + if opened is tab: + self._opened_tab = None # Consume state + return True - return opened is tab + return False def close_tab(self, tab, *, add_undo=True, new_undo=True, transfer=False, allow_firefox_behavior=True): @@ -700,7 +702,10 @@ class TabbedBrowser(QWidget): # Track opened tab for tabs.select_on_remove = 'firefox' if self.widget.count() > 0: - self._opened_tab = weakref.ref(tab) + if self._opened_tab is not None and background: + self._opened_tab = None + else: + self._opened_tab = weakref.ref(tab) if background: # Make sure the background tab has the correct initial size. diff --git a/tests/end2end/features/tabs_firefox.feature b/tests/end2end/features/tabs_firefox.feature index 549c0112e..87bfbd123 100644 --- a/tests/end2end/features/tabs_firefox.feature +++ b/tests/end2end/features/tabs_firefox.feature @@ -76,3 +76,34 @@ Feature: Tab selection on remove (firefox behavior) When I set tabs.select_on_remove to firefox And I run :tab-close --opposite Then the error "-o is not supported with 'tabs.select_on_remove' set to 'firefox'!" should be shown + + Scenario: Opening a second background tab forgets the state + When I set tabs.select_on_remove to firefox + And I open data/numbers/1.txt + And I open data/numbers/4.txt in a new tab + And I run :tab-focus 1 + And I open data/numbers/2.txt in a new background tab + And I open data/numbers/3.txt in a new background tab + And I run :tab-focus 3 + And I run :tab-close + Then the following tabs should be open: + """ + - data/numbers/1.txt + - data/numbers/2.txt + - data/numbers/4.txt (active) + """ + + Scenario: Opening a foreground tab creates a state + When I set tabs.select_on_remove to firefox + And I open data/numbers/1.txt + And I open data/numbers/4.txt in a new tab + And I run :tab-focus 1 + And I open data/numbers/2.txt in a new background tab + And I open data/numbers/3.txt in a new tab + And I run :tab-close + Then the following tabs should be open: + """ + - data/numbers/1.txt (active) + - data/numbers/4.txt + - data/numbers/2.txt + """