From d7a436568ccad55e37bac2c93e2d9e485b7f7522 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Sat, 3 Feb 2018 14:31:44 -0500 Subject: [PATCH] Add a new --no-last flag to :tab-focus --no-last prevents going to the last focused tab if a new tab does not need to be focused. --- doc/help/commands.asciidoc | 15 +++++++-------- qutebrowser/browser/commands.py | 6 ++++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index a87dc2304..82c714cdf 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -519,8 +519,7 @@ Show help about a command or setting. [[hint]] === hint -Syntax: +:hint [*--mode* 'mode'] [*--add-history*] [*--rapid*] - ['group'] ['target'] ['args' ['args' ...]]+ +Syntax: +:hint [*--mode* 'mode'] [*--add-history*] [*--rapid*] ['group'] ['target'] ['args' ['args' ...]]+ Start hinting. @@ -770,8 +769,7 @@ Do nothing. [[open]] === open -Syntax: +:open [*--related*] [*--bg*] [*--tab*] [*--window*] [*--secure*] [*--private*] - ['url']+ +Syntax: +:open [*--related*] [*--bg*] [*--tab*] [*--window*] [*--secure*] [*--private*] ['url']+ Open a URL in the current/[count]th tab. @@ -1091,9 +1089,7 @@ Load a session. [[session-save]] === session-save -Syntax: +:session-save [*--current*] [*--quiet*] [*--force*] [*--only-active-window*] - [*--with-private*] - ['name']+ +Syntax: +:session-save [*--current*] [*--quiet*] [*--force*] [*--only-active-window*] [*--with-private*] ['name']+ Save a session. @@ -1212,7 +1208,7 @@ The tab index to close [[tab-focus]] === tab-focus -Syntax: +:tab-focus ['index']+ +Syntax: +:tab-focus [*--no-last*] ['index']+ Select the tab given as argument/[count]. @@ -1224,6 +1220,9 @@ If neither count nor index are given, it behaves like tab-next. If both are give last tab. +==== optional arguments +* +*-n*+, +*--no-last*+: Whether to avoid focusing last tab if already focused. + ==== count The tab index to focus, starting with 1. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index a0c5e63ff..81835e422 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1109,7 +1109,8 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('index', choices=['last']) @cmdutils.argument('count', count=True) - def tab_focus(self, index: typing.Union[str, int] = None, count=None): + def tab_focus(self, index: typing.Union[str, int] = None, + count=None, no_last=False): """Select the tab given as argument/[count]. If neither count nor index are given, it behaves like tab-next. @@ -1121,13 +1122,14 @@ class CommandDispatcher: Negative indices count from the end, such that -1 is the last tab. count: The tab index to focus, starting with 1. + no_last: Whether to avoid focusing last tab if already focused. """ index = count if count is not None else index if index == 'last': self._tab_focus_last() return - elif index == self._current_index() + 1: + elif not no_last and index == self._current_index() + 1: self._tab_focus_last(show_error=False) return elif index is None: