diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index c54c4e04b..e69e7da14 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -841,13 +841,13 @@ How many tabs to switch forward. [[tab-only]] === tab-only -Syntax: +:tab-only [*--left*] [*--right*]+ +Syntax: +:tab-only [*--prev*] [*--next*]+ Close all tabs except for the current one. ==== optional arguments -* +*-l*+, +*--left*+: Keep tabs to the left of the current. -* +*-r*+, +*--right*+: Keep tabs to the right of the current. +* +*-p*+, +*--prev*+: Keep tabs before the current. +* +*-n*+, +*--next*+: Keep tabs after the current. [[tab-prev]] === tab-prev diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 87885d4cc..8ea978496 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -801,20 +801,20 @@ class CommandDispatcher: message.info("Zoom level: {}%".format(level)) @cmdutils.register(instance='command-dispatcher', scope='window') - def tab_only(self, left=False, right=False): + def tab_only(self, prev=False, next_=False): """Close all tabs except for the current one. Args: - left: Keep tabs to the left of the current. - right: Keep tabs to the right of the current. + prev: Keep tabs before the current. + next_: Keep tabs after the current. """ - cmdutils.check_exclusive((left, right), 'lr') + cmdutils.check_exclusive((prev, next_), 'pn') cur_idx = self._tabbed_browser.currentIndex() assert cur_idx != -1 for i, tab in enumerate(self._tabbed_browser.widgets()): - if (i == cur_idx or (left and i < cur_idx) or - (right and i > cur_idx)): + if (i == cur_idx or (prev and i < cur_idx) or + (next_ and i > cur_idx)): continue else: self._tabbed_browser.close_tab(tab) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index a8c5fed88..64bef47b1 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -1786,4 +1786,9 @@ CHANGED_KEY_COMMANDS = [ (re.compile(r'^tab-close --left$'), r'tab-close --prev'), (re.compile(r'^tab-close -r$'), r'tab-close --next'), (re.compile(r'^tab-close --right$'), r'tab-close --next'), + + (re.compile(r'^tab-only -l$'), r'tab-only --prev'), + (re.compile(r'^tab-only --left$'), r'tab-only --prev'), + (re.compile(r'^tab-only -r$'), r'tab-only --next'), + (re.compile(r'^tab-only --right$'), r'tab-only --next'), ] diff --git a/tests/end2end/features/tabs.feature b/tests/end2end/features/tabs.feature index de8742579..76dd9ddfd 100644 --- a/tests/end2end/features/tabs.feature +++ b/tests/end2end/features/tabs.feature @@ -143,29 +143,29 @@ Feature: Tab management Then the following tabs should be open: - data/numbers/3.txt (active) - Scenario: :tab-only with --left + Scenario: :tab-only with --prev 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 - And I run :tab-only --left + And I run :tab-only --prev Then the following tabs should be open: - data/numbers/1.txt - data/numbers/2.txt (active) - Scenario: :tab-only with --right + Scenario: :tab-only with --next 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 - And I run :tab-only --right + And I run :tab-only --next Then the following tabs should be open: - data/numbers/2.txt (active) - data/numbers/3.txt - Scenario: :tab-only with --left and --right - When I run :tab-only --left --right - Then the error "Only one of -l/-r can be given!" should be shown + Scenario: :tab-only with --prev and --next + When I run :tab-only --prev --next + Then the error "Only one of -p/-n can be given!" should be shown # :tab-focus