Add :tab-give and :tab-take commands and tests
This commit is contained in:
parent
b7061dc7db
commit
67437a0d5d
@ -85,11 +85,13 @@ It is possible to run or bind multiple commands by separating them with `;;`.
|
||||
|<<tab-close,tab-close>>|Close the current/[count]th tab.
|
||||
|<<tab-detach,tab-detach>>|Detach the current tab to its own window.
|
||||
|<<tab-focus,tab-focus>>|Select the tab given as argument/[count].
|
||||
|<<tab-give,tab-give>>|Give the current tab to another window.
|
||||
|<<tab-move,tab-move>>|Move the current tab according to the argument and [count].
|
||||
|<<tab-next,tab-next>>|Switch to the next tab, or switch [count] tabs forward.
|
||||
|<<tab-only,tab-only>>|Close all tabs except for the current one.
|
||||
|<<tab-pin,tab-pin>>|Pin/Unpin the current/[count]th tab.
|
||||
|<<tab-prev,tab-prev>>|Switch to the previous tab, or switch [count] tabs back.
|
||||
|<<tab-take,tab-take>>|Take a tab from another window.
|
||||
|<<unbind,unbind>>|Unbind a keychain.
|
||||
|<<undo,undo>>|Re-open a closed tab.
|
||||
|<<version,version>>|Show version information.
|
||||
@ -967,6 +969,15 @@ If neither count nor index are given, it behaves like tab-next. If both are give
|
||||
==== count
|
||||
The tab index to focus, starting with 1.
|
||||
|
||||
[[tab-give]]
|
||||
=== tab-give
|
||||
Syntax: +:tab-give 'win-id'+
|
||||
|
||||
Give the current tab to another window.
|
||||
|
||||
==== positional arguments
|
||||
* +'win-id'+: The window ID of the window to give the current tab to.
|
||||
|
||||
[[tab-move]]
|
||||
=== tab-move
|
||||
Syntax: +:tab-move ['index']+
|
||||
@ -1019,6 +1030,16 @@ Switch to the previous tab, or switch [count] tabs back.
|
||||
==== count
|
||||
How many tabs to switch back.
|
||||
|
||||
[[tab-take]]
|
||||
=== tab-take
|
||||
Syntax: +:tab-take 'index'+
|
||||
|
||||
Take a tab from another window.
|
||||
|
||||
==== positional arguments
|
||||
* +'index'+: The [win_id/]index of the tab to take. Or a substring in which case the closest match will be taken.
|
||||
|
||||
|
||||
[[unbind]]
|
||||
=== unbind
|
||||
Syntax: +:unbind [*--mode* 'mode'] 'key'+
|
||||
|
@ -523,6 +523,39 @@ class CommandDispatcher:
|
||||
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):
|
||||
"""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.
|
||||
"""
|
||||
tabbed_browser, tab = self._resolve_buffer_index(index)
|
||||
|
||||
if tabbed_browser is self._tabbed_browser:
|
||||
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)
|
||||
|
||||
@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.
|
||||
|
||||
Args:
|
||||
win_id: The window ID of the window to give the current tab to.
|
||||
"""
|
||||
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)
|
||||
tabbed_browser.tabopen(self._current_url())
|
||||
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."""
|
||||
history = self._current_widget().history
|
||||
|
@ -122,3 +122,22 @@ def buffer(*, info=None): # pylint: disable=unused-argument
|
||||
model.add_category(cat)
|
||||
|
||||
return model
|
||||
|
||||
|
||||
def window(*, info=None): # pylint: disable=unused-argument
|
||||
"""A model to complete on all open windows."""
|
||||
model = completionmodel.CompletionModel(column_widths=(6, 30, 64))
|
||||
|
||||
windows = []
|
||||
|
||||
for win_id in objreg.window_registry:
|
||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||
window=win_id)
|
||||
tab_titles = (tab.title() for tab in tabbed_browser.widgets())
|
||||
windows.append(("{}".format(win_id),
|
||||
objreg.window_registry[win_id].windowTitle(),
|
||||
", ".join(tab_titles)))
|
||||
|
||||
model.add_category(listcategory.ListCategory("Windows", windows))
|
||||
|
||||
return model
|
||||
|
@ -1010,6 +1010,56 @@ Feature: Tab management
|
||||
And I run :buffer "1/2/3"
|
||||
Then the error "No matching tab for: 1/2/3" should be shown
|
||||
|
||||
# :tab-take
|
||||
|
||||
@xfail_norun
|
||||
Scenario: Take a tab from another window
|
||||
Given I have a fresh instance
|
||||
When I open data/numbers/1.txt
|
||||
And I open data/numbers/2.txt in a new window
|
||||
And I run :tab-take 0/1
|
||||
Then the session should look like:
|
||||
windows:
|
||||
- tabs:
|
||||
- history:
|
||||
- url: about:blank
|
||||
- tabs:
|
||||
- history:
|
||||
- url: http://localhost:*/data/numbers/2.txt
|
||||
- history:
|
||||
- url: http://localhost:*/data/numbers/1.txt
|
||||
|
||||
Scenario: Take a tab from the same window
|
||||
Given I have a fresh instance
|
||||
When I open data/numbers/1.txt
|
||||
And I run :tab-take 0/1
|
||||
Then the error "Can't take a tab from the same window" should be shown
|
||||
|
||||
# :tab-give
|
||||
|
||||
@xfail_norun
|
||||
Scenario: Give a tab to another window
|
||||
Given I have a fresh instance
|
||||
When I open data/numbers/1.txt
|
||||
And I open data/numbers/2.txt in a new window
|
||||
And I run :tab-give 0
|
||||
Then the session should look like:
|
||||
windows:
|
||||
- tabs:
|
||||
- history:
|
||||
- url: http://localhost:*/data/numbers/1.txt
|
||||
- history:
|
||||
- url: http://localhost:*/data/numbers/2.txt
|
||||
- tabs:
|
||||
- history:
|
||||
- url: about:blank
|
||||
|
||||
Scenario: Give a tab to the same window
|
||||
Given I have a fresh instance
|
||||
When I open data/numbers/1.txt
|
||||
And I run :tab-give 0
|
||||
Then the error "Can't give a tab to the same window" should be shown
|
||||
|
||||
# Other
|
||||
|
||||
Scenario: Using :tab-next after closing last tab (#1448)
|
||||
|
Loading…
Reference in New Issue
Block a user