From 5e5c778b4a1418bc4f06cf78885b8a895f5cf720 Mon Sep 17 00:00:00 2001 From: Tim Gadanidis Date: Mon, 1 Nov 2021 22:18:46 -0400 Subject: Always close tabs when given or taken Add an optional boolean argument to `tabbed_browser.close_tab()` called `transfer` which indicates whether the tab is closing as a result of being given to another window (`tab-give`) or taken by another window (`tab-take`). If so, the tab will always close, even if it is the last tab in the window and `tabs.last_close` is not set to 'close'. --- qutebrowser/browser/commands.py | 5 +++-- qutebrowser/mainwindow/tabbedbrowser.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index f3438aaa8..5937e7604 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -451,7 +451,7 @@ class CommandDispatcher: self._open(tab.url(), tab=True) if not keep: - tabbed_browser.close_tab(tab, add_undo=False) + tabbed_browser.close_tab(tab, add_undo=False, transfer=True) @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('win_id', completion=miscmodels.window) @@ -500,7 +500,8 @@ class CommandDispatcher: tabbed_browser.tabopen(self._current_url()) if not keep: self._tabbed_browser.close_tab(self._current_widget(), - add_undo=False) + add_undo=False, + transfer=True) def _back_forward(self, tab, bg, window, count, forward, index=None): """Helper function for :back/:forward.""" diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index e081284ee..47bb32a6f 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -406,13 +406,14 @@ class TabbedBrowser(QWidget): else: yes_action() - def close_tab(self, tab, *, add_undo=True, new_undo=True): + def close_tab(self, tab, *, add_undo=True, new_undo=True, transfer=False): """Close a tab. Args: tab: The QWebView to be closed. add_undo: Whether the tab close can be undone. new_undo: Whether the undo entry should be a new item in the stack. + transfer: Whether the tab is closing because it is moving to a new window. """ if config.val.tabs.tabs_are_windows: last_close = 'close' @@ -421,13 +422,13 @@ class TabbedBrowser(QWidget): count = self.widget.count() - if last_close == 'ignore' and count == 1: + if last_close == 'ignore' and count == 1 and not transfer: return self._remove_tab(tab, add_undo=add_undo, new_undo=new_undo) if count == 1: # We just closed the last tab above. - if last_close == 'close': + if last_close == 'close' or transfer: self.close_window.emit() elif last_close == 'blank': self.load_url(QUrl('about:blank'), newtab=True) -- cgit v1.2.3-54-g00ecf From 47f6bd85af4bf6d65b4a0ef0e460e1e557226264 Mon Sep 17 00:00:00 2001 From: Tim Gadanidis Date: Sat, 13 Nov 2021 15:50:26 -0500 Subject: Simplify logic --- qutebrowser/mainwindow/tabbedbrowser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 47bb32a6f..8c6ac2424 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -415,20 +415,20 @@ class TabbedBrowser(QWidget): new_undo: Whether the undo entry should be a new item in the stack. transfer: Whether the tab is closing because it is moving to a new window. """ - if config.val.tabs.tabs_are_windows: + if config.val.tabs.tabs_are_windows or transfer: last_close = 'close' else: last_close = config.val.tabs.last_close count = self.widget.count() - if last_close == 'ignore' and count == 1 and not transfer: + if last_close == 'ignore' and count == 1: return self._remove_tab(tab, add_undo=add_undo, new_undo=new_undo) if count == 1: # We just closed the last tab above. - if last_close == 'close' or transfer: + if last_close == 'close': self.close_window.emit() elif last_close == 'blank': self.load_url(QUrl('about:blank'), newtab=True) -- cgit v1.2.3-54-g00ecf From a50f6dc2ea6baffcbaef2c7bc3c890e18631802f Mon Sep 17 00:00:00 2001 From: Tim Gadanidis Date: Sun, 21 Nov 2021 00:00:22 -0500 Subject: Add tests for closing last tab when giving/taking --- tests/end2end/features/tabs.feature | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/end2end/features/tabs.feature b/tests/end2end/features/tabs.feature index c9d983755..dae19e445 100644 --- a/tests/end2end/features/tabs.feature +++ b/tests/end2end/features/tabs.feature @@ -1349,6 +1349,24 @@ Feature: Tab management And I run :tab-take 0/1 Then the error "Can't take tabs when using windows as tabs" should be shown + Scenario: Close the last tab of a window when taken by another window + Given I have a fresh instance + When I open data/numbers/1.txt + And I run :tab-only + And I open data/numbers/2.txt in a new window + And I set tabs.last_close to ignore + And I run :tab-take 1/1 + And I wait until data/numbers/2.txt is loaded + Then the session should look like: + windows: + - tabs: + - history: + - url: about:blank + - url: http://localhost:*/data/numbers/1.txt + - active: true + history: + - url: http://localhost:*/data/numbers/2.txt + # :tab-give @xfail_norun # Needs qutewm @@ -1406,6 +1424,23 @@ Feature: Tab management And I run :tab-give 0 Then the error "Can't give tabs when using windows as tabs" should be shown + Scenario: Close the last tab of a window when given to another window + Given I have a fresh instance + When I open data/numbers/1.txt + And I run :tab-only + And I open data/numbers/2.txt in a new window + And I set tabs.last_close to ignore + And I run :tab-give 1 + And I wait until data/numbers/1.txt is loaded + Then the session should look like: + windows: + - tabs: + - active: true + history: + - url: http://localhost:*/data/numbers/2.txt + - history: + - url: http://localhost:*/data/numbers/1.txt + # Other Scenario: Using :tab-next after closing last tab (#1448) -- cgit v1.2.3-54-g00ecf From 73aed03a7f9bb630ba6412abff22f52c56c00485 Mon Sep 17 00:00:00 2001 From: Tim Gadanidis Date: Mon, 22 Nov 2021 11:32:43 -0500 Subject: Skip failing tests on Windows --- tests/end2end/features/tabs.feature | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/end2end/features/tabs.feature b/tests/end2end/features/tabs.feature index dae19e445..ab6098a3e 100644 --- a/tests/end2end/features/tabs.feature +++ b/tests/end2end/features/tabs.feature @@ -1349,6 +1349,7 @@ Feature: Tab management And I run :tab-take 0/1 Then the error "Can't take tabs when using windows as tabs" should be shown + @windows_skip Scenario: Close the last tab of a window when taken by another window Given I have a fresh instance When I open data/numbers/1.txt @@ -1424,6 +1425,7 @@ Feature: Tab management And I run :tab-give 0 Then the error "Can't give tabs when using windows as tabs" should be shown + @windows_skip Scenario: Close the last tab of a window when given to another window Given I have a fresh instance When I open data/numbers/1.txt -- cgit v1.2.3-54-g00ecf