diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 4ffb2be6f..50cad0df2 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -22,6 +22,12 @@ Added - New `:edit-url` command to edit the URL in an external editor. +Changed +~~~~~~~ + +- `:tab-focus` can now take a negative index to focus the nth tab counted from + the right. + v0.6.0 ------ diff --git a/README.asciidoc b/README.asciidoc index dfd3eb3f7..c5b6c3030 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -218,6 +218,7 @@ Contributors, sorted by the number of commits in descending order: * Samuel Loury * Matthias Lisin * Marcel Schilling +* Johannes Martinsson * Jean-Christophe Petkovich * Jay Kamat * Helen Sherwood-Taylor diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 45d19ad86..5d4786bbe 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -719,7 +719,8 @@ Select the tab given as argument/[count]. If neither count nor index are given, it behaves like tab-next. ==== positional arguments -* +'index'+: The tab index to focus, starting with 1. The special value `last` focuses the last focused tab. +* +'index'+: The tab index to focus, starting with 1. The special value `last` focuses the last focused tab. Negative indexes + counts from the end, such that -1 is the last tab. ==== count diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 4fd64c1bf..278380578 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -900,7 +900,8 @@ class CommandDispatcher: Args: index: The tab index to focus, starting with 1. The special value - `last` focuses the last focused tab. + `last` focuses the last focused tab. Negative indexes + counts from the end, such that -1 is the last tab. count: The tab index to focus, starting with 1. """ if index == 'last': @@ -909,6 +910,8 @@ class CommandDispatcher: if index is None and count is None: self.tab_next() return + if index is not None and index < 0: + index = self._count() + index + 1 try: idx = cmdutils.arg_or_count(index, count, default=1, countzero=self._count()) diff --git a/tests/integration/features/tabs.feature b/tests/integration/features/tabs.feature index 630fa6279..6603817d9 100644 --- a/tests/integration/features/tabs.feature +++ b/tests/integration/features/tabs.feature @@ -228,6 +228,34 @@ Feature: Tab management - data/numbers/2.txt - data/numbers/3.txt + Scenario: :tab-focus with -1 + When I open data/numbers/1.txt + And I open data/numbers/2.txt in a new tab + And I open data/numbers/3.txt in a new tab + And I run :tab-focus 1 + And I run :tab-focus -1 + Then the following tabs should be open: + - data/numbers/1.txt + - data/numbers/2.txt + - data/numbers/3.txt (active) + + Scenario: :tab-focus negative index + When I open data/numbers/1.txt + And I open data/numbers/2.txt in a new tab + And I open data/numbers/3.txt in a new tab + And I run :tab-focus -2 + Then the following tabs should be open: + - data/numbers/1.txt + - data/numbers/2.txt (active) + - data/numbers/3.txt + + Scenario: :tab-focus with invalid negative index + When I open data/numbers/1.txt + And I open data/numbers/2.txt in a new tab + And I open data/numbers/3.txt in a new tab + And I run :tab-focus -5 + Then the error "There's no tab with index -1!" should be shown + Scenario: :tab-focus last with no last focused tab Given I have a fresh instance And I run :tab-focus last