Add :tab-{give,take} --keep

This commit is contained in:
Florian Bruhin 2018-10-01 16:53:03 +02:00
parent 8f33b89a57
commit 8a7c1b66a4
3 changed files with 19 additions and 7 deletions

View File

@ -85,6 +85,8 @@ Changed
- '@@' now repeats the last run macro.
- The `content.host_blocking.lists` setting now accepts a `file://` URL to a
directory, and reads all files in that directory.
- The `:tab-give` and `:tab-take` command now have a new flag `--keep` which
causes them to keep the old tab around.
Fixed
~~~~~

View File

@ -1261,7 +1261,7 @@ The tab index to focus, starting with 1.
[[tab-give]]
=== tab-give
Syntax: +:tab-give ['win-id']+
Syntax: +:tab-give [*--keep*] ['win-id']+
Give the current tab to a new or existing window if win_id given.
@ -1270,6 +1270,9 @@ 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.
==== optional arguments
* +*-k*+, +*--keep*+: If given, keep the old tab around.
==== count
Overrides win_id (index starts at 1 for win_id=0).
@ -1334,7 +1337,7 @@ How many tabs to switch back.
[[tab-take]]
=== tab-take
Syntax: +:tab-take 'index'+
Syntax: +:tab-take [*--keep*] 'index'+
Take a tab from another window.
@ -1342,6 +1345,9 @@ Take a tab from another window.
* +'index'+: The [win_id/]index of the tab to take. Or a substring in which case the closest match will be taken.
==== optional arguments
* +*-k*+, +*--keep*+: If given, keep the old tab around.
==== note
* This command does not split arguments after the last argument and handles quotes literally.

View File

@ -493,12 +493,13 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window',
maxsplit=0)
@cmdutils.argument('index', completion=miscmodels.other_buffer)
def tab_take(self, index):
def tab_take(self, index, keep=False):
"""Take a tab from another window.
Args:
index: The [win_id/]index of the tab to take. Or a substring
in which case the closest match will be taken.
keep: If given, keep the old tab around.
"""
tabbed_browser, tab = self._resolve_buffer_index(index)
@ -506,18 +507,20 @@ class CommandDispatcher:
raise cmdexc.CommandError("Can't take a tab from the same window")
self._open(tab.url(), tab=True)
tabbed_browser.close_tab(tab, add_undo=False)
if not keep:
tabbed_browser.close_tab(tab, add_undo=False)
@cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('win_id', completion=miscmodels.window)
@cmdutils.argument('count', count=True)
def tab_give(self, win_id: int = None, count=None):
def tab_give(self, win_id: int = None, keep=False, count=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.
keep: If given, keep the old tab around.
count: Overrides win_id (index starts at 1 for win_id=0).
"""
if count is not None:
@ -527,7 +530,7 @@ class CommandDispatcher:
raise cmdexc.CommandError("Can't give a tab to the same window")
if win_id is None:
if self._count() < 2:
if self._count() < 2 and not keep:
raise cmdexc.CommandError("Cannot detach from a window with "
"only one tab")
@ -542,7 +545,8 @@ class CommandDispatcher:
window=win_id)
tabbed_browser.tabopen(self._current_url())
self._tabbed_browser.close_tab(self._current_widget(), add_undo=False)
if not keep:
self._tabbed_browser.close_tab(self._current_widget(), add_undo=False)
def _back_forward(self, tab, bg, window, count, forward):
"""Helper function for :back/:forward."""