diff options
author | Iordanis Grigoriou <iordanis.grigoriou@gmail.com> | 2017-06-19 15:48:17 +0200 |
---|---|---|
committer | Iordanis Grigoriou <iordanis.grigoriou@gmail.com> | 2017-06-19 15:48:17 +0200 |
commit | f0ff02fcb2b23af9429fe10a100380f7d3ea8d57 (patch) | |
tree | 4009f6f9f8dd59d25bc50f9383713372f143ea4b | |
parent | e14477375b9744afc77b77e3a56e537e3f3b563a (diff) | |
download | qutebrowser-f0ff02fcb2b23af9429fe10a100380f7d3ea8d57.tar.gz qutebrowser-f0ff02fcb2b23af9429fe10a100380f7d3ea8d57.zip |
Avoid throwing exception when no last focused tab exists
-rw-r--r-- | qutebrowser/browser/commands.py | 12 | ||||
-rw-r--r-- | tests/end2end/features/javascript.feature | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 810e357ce..2f94412eb 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -157,12 +157,14 @@ class CommandDispatcher: else: return None - def _tab_focus_last(self): + def _tab_focus_last(self, show_error=True): """Select the tab which was last focused.""" try: tab = objreg.get('last-focused-tab', scope='window', window=self._win_id) except KeyError: + if not show_error: + return raise cmdexc.CommandError("No last focused tab!") idx = self._tabbed_browser.indexOf(tab) if idx == -1: @@ -1078,11 +1080,13 @@ class CommandDispatcher: """ index = count if count is not None else index - if index in ('last', self._current_index() + 1): + if index == 'last': self._tab_focus_last() return - - if index is None: + elif index == self._current_index() + 1: + self._tab_focus_last(show_error=False) + return + elif index is None: self.tab_next() return diff --git a/tests/end2end/features/javascript.feature b/tests/end2end/features/javascript.feature index efdd692ac..c16d1273e 100644 --- a/tests/end2end/features/javascript.feature +++ b/tests/end2end/features/javascript.feature @@ -50,7 +50,7 @@ Feature: Javascript stuff And I open data/javascript/window_open.html in a new tab And I run :click-element id open-normal And I wait for "Changing title for idx 2 to 'about:blank'" in the log - And I run :tab-focus 2 + And I run :buffer window_open.html And I run :click-element id close-twice And I wait for "Focus object changed: *" in the log Then no crash should happen |