From 29f66dcd9591016585602566af46cbbbb63efb2b Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Wed, 4 Oct 2017 13:35:40 +1100 Subject: [PATCH] Merge :tab-detach with :tab-give --- doc/help/commands.asciidoc | 13 ++++----- qutebrowser/browser/commands.py | 28 +++++++++--------- tests/end2end/features/invoke.feature | 4 +-- tests/end2end/features/tabs.feature | 42 +++++++++++++-------------- 4 files changed, 41 insertions(+), 46 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index e166e51eb..fed4e88d4 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -83,9 +83,8 @@ It is possible to run or bind multiple commands by separating them with `;;`. |<>|Stop loading in the current/[count]th tab. |<>|Duplicate the current tab. |<>|Close the current/[count]th tab. -|<>|Detach the current tab to its own window. |<>|Select the tab given as argument/[count]. -|<>|Give the current tab to another window. +|<>|Give the current tab to a new or existing window if win_id given. |<>|Move the current tab according to the argument and [count]. |<>|Switch to the next tab, or switch [count] tabs forward. |<>|Close all tabs except for the current one. @@ -948,10 +947,6 @@ Close the current/[count]th tab. ==== count The tab index to close -[[tab-detach]] -=== tab-detach -Detach the current tab to its own window. - [[tab-focus]] === tab-focus Syntax: +:tab-focus ['index']+ @@ -971,9 +966,11 @@ The tab index to focus, starting with 1. [[tab-give]] === tab-give -Syntax: +:tab-give 'win-id'+ +Syntax: +:tab-give ['win-id']+ -Give the current tab to another window. +Give the current tab to a new or existing window if win_id given. + +If no win_id is given, the tab will get detached into a new window. ==== positional arguments * +'win-id'+: The window ID of the window to give the current tab to. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index b7ed82af9..a3eed85df 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -513,16 +513,6 @@ class CommandDispatcher: new_tabbed_browser.set_tab_pinned(newtab, curtab.data.pinned) return newtab - @cmdutils.register(instance='command-dispatcher', scope='window') - def tab_detach(self): - """Detach the current tab to its own window.""" - if self._count() < 2: - raise cmdexc.CommandError("Cannot detach one tab.") - url = self._current_url() - self._open(url, window=True) - cur_widget = self._current_widget() - self._tabbed_browser.close_tab(cur_widget, add_undo=False) - @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('index', completion=miscmodels.buffer) def tab_take(self, index): @@ -542,8 +532,10 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('win_id', completion=miscmodels.window) - def tab_give(self, win_id: int): - """Give the current tab to another window. + def tab_give(self, win_id: int = None): + """Give the current tab to a new or existing window if win_id given. + + If no win_id is given, the tab will get detached into a new window. Args: win_id: The window ID of the window to give the current tab to. @@ -551,8 +543,16 @@ class CommandDispatcher: if win_id == self._win_id: raise cmdexc.CommandError("Can't give a tab to the same window") - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=win_id) + if win_id is not None: + tabbed_browser = objreg.get('tabbed-browser', scope='window', + window=win_id) + else: + if self._count() < 2: + raise cmdexc.CommandError("Cannot detach from a window with " + "only one tab") + + tabbed_browser = self._new_tabbed_browser( + private=self._tabbed_browser.private) tabbed_browser.tabopen(self._current_url()) self._tabbed_browser.close_tab(self._current_widget(), add_undo=False) diff --git a/tests/end2end/features/invoke.feature b/tests/end2end/features/invoke.feature index d343db593..9be38659e 100644 --- a/tests/end2end/features/invoke.feature +++ b/tests/end2end/features/invoke.feature @@ -74,12 +74,12 @@ Feature: Invoking a new process # issue #1060 - Scenario: Using target_window = first-opened after tab-detach + Scenario: Using target_window = first-opened after tab-give When I set new_instance_open_target to tab And I set new_instance_open_target_window to first-opened And I open data/title.html And I open data/search.html in a new tab - And I run :tab-detach + And I run :tab-give And I wait until data/search.html is loaded And I open data/hello.txt as a URL Then the session should look like: diff --git a/tests/end2end/features/tabs.feature b/tests/end2end/features/tabs.feature index ba20f9a75..4c35547dc 100644 --- a/tests/end2end/features/tabs.feature +++ b/tests/end2end/features/tabs.feature @@ -638,28 +638,6 @@ Feature: Tab management And I run :tab-clone Then no crash should happen - # :tab-detach - - Scenario: Detaching a tab - When I open data/numbers/1.txt - And I open data/numbers/2.txt in a new tab - And I run :tab-detach - 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 - - tabs: - - history: - - url: http://localhost:*/data/numbers/2.txt - - Scenario: Detach tab from window with only one tab - When I open data/hello.txt - And I run :tab-detach - Then the error "Cannot detach one tab." should be shown - # :undo Scenario: Undo without any closed tabs @@ -1060,6 +1038,26 @@ Feature: Tab management And I run :tab-give 0 Then the error "Can't give a tab to the same window" should be shown + Scenario: Give a tab to a new window + When I open data/numbers/1.txt + And I open data/numbers/2.txt in a new tab + And I run :tab-give + 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 + - tabs: + - history: + - url: http://localhost:*/data/numbers/2.txt + + Scenario: Give a tab from window with only one tab + When I open data/hello.txt + And I run :tab-give + Then the error "Cannot detach from a window with only one tab" should be shown + # Other Scenario: Using :tab-next after closing last tab (#1448)