From 6202477db58d5cca9f2e5d2835e939d5e6d73aca Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 7 Oct 2014 20:56:47 +0200 Subject: [PATCH] Add --left/--right arguments to :tab-only. Closes #46. --- qutebrowser/browser/commands.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index da9369411..f71b7e426 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -622,13 +622,24 @@ class CommandDispatcher: tab.zoom_perc(level) @cmdutils.register(instance='command-dispatcher', scope='window') - def tab_only(self): - """Close all tabs except for the current one.""" + def tab_only(self, left=False, right=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. + """ + cmdutils.check_exclusive((left, right), 'lr') tabbed_browser = self._tabbed_browser() - for tab in tabbed_browser.widgets(): - if tab is self._current_widget(): + cur_idx = tabbed_browser.currentIndex() + assert cur_idx != -1 + + for i, tab in enumerate(tabbed_browser.widgets()): + if (i == cur_idx or (left and i < cur_idx) or + (right and i > cur_idx)): continue - tabbed_browser.close_tab(tab) + else: + tabbed_browser.close_tab(tab) @cmdutils.register(instance='command-dispatcher', scope='window') def undo(self):