Abort :back/:forward at beginning/end of history.
This commit is contained in:
parent
eef760359c
commit
a4d15b550e
@ -413,20 +413,27 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
def _back_forward(self, tab, bg, window, count, forward):
|
def _back_forward(self, tab, bg, window, count, forward):
|
||||||
"""Helper function for :back/:forward."""
|
"""Helper function for :back/:forward."""
|
||||||
if (not forward and not
|
# Catch common cases before e.g. cloning tab
|
||||||
self._current_widget().page().history().canGoBack()):
|
history = self._current_widget().page().history()
|
||||||
|
if not forward and not history.canGoBack():
|
||||||
raise cmdexc.CommandError("At beginning of history.")
|
raise cmdexc.CommandError("At beginning of history.")
|
||||||
if (forward and not
|
elif forward and not history.canGoForward():
|
||||||
self._current_widget().page().history().canGoForward()):
|
|
||||||
raise cmdexc.CommandError("At end of history.")
|
raise cmdexc.CommandError("At end of history.")
|
||||||
|
|
||||||
if tab or bg or window:
|
if tab or bg or window:
|
||||||
widget = self.tab_clone(bg, window)
|
widget = self.tab_clone(bg, window)
|
||||||
else:
|
else:
|
||||||
widget = self._current_widget()
|
widget = self._current_widget()
|
||||||
|
|
||||||
|
history = widget.page().history()
|
||||||
for _ in range(count):
|
for _ in range(count):
|
||||||
if forward:
|
if forward:
|
||||||
|
if not history.canGoForward():
|
||||||
|
raise cmdexc.CommandError("At end of history.")
|
||||||
widget.forward()
|
widget.forward()
|
||||||
else:
|
else:
|
||||||
|
if not history.canGoBack():
|
||||||
|
raise cmdexc.CommandError("At beginning of history.")
|
||||||
widget.back()
|
widget.back()
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
|
@ -43,6 +43,19 @@ Feature: Going back and forward.
|
|||||||
url: http://localhost:*/data/backforward/1.txt
|
url: http://localhost:*/data/backforward/1.txt
|
||||||
- url: http://localhost:*/data/backforward/2.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
|
Scenario: Going back in a new background tab
|
||||||
Given I open data/backforward/1.txt
|
Given I open data/backforward/1.txt
|
||||||
When I open data/backforward/2.txt
|
When I open data/backforward/2.txt
|
||||||
|
Loading…
Reference in New Issue
Block a user