added --open arg to :tab-select

This commit is contained in:
Max 2022-08-22 19:48:04 +06:00
parent c9613e09e5
commit 81ff5abbfe
2 changed files with 13 additions and 3 deletions

View File

@ -1504,7 +1504,7 @@ How many tabs to switch back.
[[tab-select]]
=== tab-select
Syntax: +:tab-select ['index']+
Syntax: +:tab-select [*--open*] ['index']+
Select tab by index or url/title best match.
@ -1513,6 +1513,8 @@ Focuses window if necessary when index is given. If both index and count are giv
==== positional arguments
* +'index'+: The [win_id/]index of the tab to focus. Or a substring in which case the closest match will be focused.
==== optional arguments
* +*-o*+, +*--open*+: If index is a substring and it didn't match any tab, open it in a new tab.
==== count
The tab index to focus, starting with 1.

View File

@ -932,7 +932,7 @@ class CommandDispatcher:
maxsplit=0)
@cmdutils.argument('index', completion=miscmodels.tabs)
@cmdutils.argument('count', value=cmdutils.Value.count)
def tab_select(self, index=None, count=None):
def tab_select(self, index=None, open=False, count=None):
"""Select tab by index or url/title best match.
Focuses window if necessary when index is given. If both index and
@ -944,6 +944,7 @@ class CommandDispatcher:
index: The [win_id/]index of the tab to focus. Or a substring
in which case the closest match will be focused.
count: The tab index to focus, starting with 1.
open: If index is a substring and it didn't match any tab, open it in a new tab.
"""
if count is None and index is None:
self.openurl('qute://tabs/', tab=True)
@ -952,7 +953,14 @@ class CommandDispatcher:
if count is not None:
index = str(count)
tabbed_browser, tab = self._resolve_tab_index(index)
tabbed_browser, tab = None, None
try:
tabbed_browser, tab = self._resolve_tab_index(index)
except cmdutils.CommandError:
if open:
self.openurl(index, tab=True)
return
raise
window = tabbed_browser.widget.window()
mainwindow.raise_window(window)