From 87e94a2c688250d155869c106f08a5332ff2a0da Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 9 May 2014 11:29:10 +0200 Subject: [PATCH] Add T command / refactor focus_tab --- TODO | 3 --- qutebrowser/config/configdata.py | 1 + qutebrowser/widgets/_tabbedbrowser.py | 22 +++++++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 2e4404d1a..0508bf61a 100644 --- a/TODO +++ b/TODO @@ -284,9 +284,6 @@ Open quickmark in a new tab (command tab_quickmark, aliases: tabqmarks). tab-handling ------------ -[n]T -Focus nth tab, first tab if n is omitted or last tab if n is 0. (command focus_tab, aliases: tab). - C-Tab Toggle between current and last focused tab (command toggle_tab, aliases: ttab) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 5ddfa4633..c6d55023a 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -548,6 +548,7 @@ DATA = OrderedDict([ ('ga', 'tabopen about:blank'), ('d', 'tabclose'), ('co', 'only'), + ('T', 'focus_tab'), ('J', 'tabnext'), ('K', 'tabprev'), ('r', 'reload'), diff --git a/qutebrowser/widgets/_tabbedbrowser.py b/qutebrowser/widgets/_tabbedbrowser.py index 038f5d5b9..b1ccc1917 100644 --- a/qutebrowser/widgets/_tabbedbrowser.py +++ b/qutebrowser/widgets/_tabbedbrowser.py @@ -364,15 +364,23 @@ class TabbedBrowser(TabWidget): Args: index: The tab index to focus, starting with 1. """ - if ((index is None and count is None) or - (index is not None and count is not None)): + if index is not None and count is not None: message.error("Either argument or count must be given!") return - try: - idx = int(index) if index is not None else count - except ValueError: - message.error("Argument ({}) needs to be a number!".format(index)) - return + elif index is not None: + try: + idx = int(index) + except ValueError: + message.error("Argument ({}) needs to be a number!".format( + index)) + return + elif count is not None: + if count == 0: + idx = self.count() + else: + idx = count + else: + idx = 1 if 1 <= idx <= self.count(): self.setCurrentIndex(idx - 1) else: