From a4d15b550e9669c0b900dead0d21779502b190d1 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 16 Nov 2015 19:03:07 +0100 Subject: [PATCH] Abort :back/:forward at beginning/end of history. --- qutebrowser/browser/commands.py | 15 +++++++++++---- tests/integration/features/backforward.feature | 13 +++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 27cc9bc81..15c8168b3 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -413,20 +413,27 @@ class CommandDispatcher: def _back_forward(self, tab, bg, window, count, forward): """Helper function for :back/:forward.""" - if (not forward and not - self._current_widget().page().history().canGoBack()): + # Catch common cases before e.g. cloning tab + history = self._current_widget().page().history() + if not forward and not history.canGoBack(): raise cmdexc.CommandError("At beginning of history.") - if (forward and not - self._current_widget().page().history().canGoForward()): + elif forward and not history.canGoForward(): raise cmdexc.CommandError("At end of history.") + if tab or bg or window: widget = self.tab_clone(bg, window) else: widget = self._current_widget() + + history = widget.page().history() for _ in range(count): if forward: + if not history.canGoForward(): + raise cmdexc.CommandError("At end of history.") widget.forward() else: + if not history.canGoBack(): + raise cmdexc.CommandError("At beginning of history.") widget.back() @cmdutils.register(instance='command-dispatcher', scope='window', diff --git a/tests/integration/features/backforward.feature b/tests/integration/features/backforward.feature index 2ee0486b3..f34d84f3a 100644 --- a/tests/integration/features/backforward.feature +++ b/tests/integration/features/backforward.feature @@ -43,6 +43,19 @@ Feature: Going back and forward. url: http://localhost:*/data/backforward/1.txt - url: http://localhost:*/data/backforward/2.txt + Scenario: Going back in a new tab without history + Given I open data/backforward/1.txt + When I run :tab-only + And I run :back -t + Then the error "At beginning of history." should be shown. + Then the session should look like: + windows: + - tabs: + - active: true + history: + - active: true + url: http://localhost:*/data/backforward/1.txt + Scenario: Going back in a new background tab Given I open data/backforward/1.txt When I open data/backforward/2.txt