From b68f22541cd82e065c613342692d74eb3ce07ada Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 3 Aug 2014 00:39:39 +0200 Subject: [PATCH] Merge tab-focus-last into tab-focus. --- qutebrowser/browser/commands.py | 26 +++++++++++++++----------- qutebrowser/config/configdata.py | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index c42662802..cd917ed67 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -125,6 +125,16 @@ class CommandDispatcher: elif direction == '+': return self._tabs.currentIndex() + delta + def _tab_focus_last(self): + """Select the tab which was last focused.""" + if self._tabs.last_focused is None: + raise CommandError("No last focused tab!") + idx = self._tabs.indexOf(self._tabs.last_focused) + if idx == -1: + raise CommandError("Last focused tab vanished!") + self._tabs.setCurrentIndex(idx) + + def _editor_cleanup(self, oshandle, filename): """Clean up temporary file when the editor was closed.""" os.close(oshandle) @@ -574,9 +584,13 @@ class CommandDispatcher: """Select the tab given as argument/[count]. Args: - index: The tab index to focus, starting with 1. + index: The tab index to focus, starting with 1. The special value + `last` focuses the last focused tab. count: The tab index to focus, starting with 1. """ + if index == 'last': + self._tab_focus_last() + return try: idx = cmdutils.arg_or_count(index, count, default=1, countzero=self._tabs.count()) @@ -619,16 +633,6 @@ class CommandDispatcher: self._tabs.insertTab(new_idx, tab, icon, label) self._tabs.setCurrentIndex(new_idx) - @cmdutils.register(instance='mainwindow.tabs.cmd') - def tab_focus_last(self): - """Select the tab which was last focused.""" - if self._tabs.last_focused is None: - raise CommandError("No last focused tab!") - idx = self._tabs.indexOf(self._tabs.last_focused) - if idx == -1: - raise CommandError("Last focused tab vanished!") - self._tabs.setCurrentIndex(idx) - @cmdutils.register(instance='mainwindow.tabs.cmd', split=False) def spawn(self, *args): """Spawn a command in a shell. diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index eb8c95fd9..d83e229e7 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -650,7 +650,7 @@ DATA = OrderedDict([ ('wi', 'inspector'), ('gd', 'download-page'), ('ad', 'cancel-download'), - ('', 'tab-focus-last'), + ('', 'tab-focus last'), ('', 'enter-mode passthrough'), ('', 'quit'), ('', 'undo'),