Skip intermediate pages with :back/:forward and a count

This commit is contained in:
Iordanis Grigoriou 2017-07-10 00:28:47 +02:00
parent 0e8175b8eb
commit c6ed4fe4f9
4 changed files with 56 additions and 17 deletions

View File

@ -477,6 +477,12 @@ class AbstractHistory:
def can_go_forward(self):
raise NotImplementedError
def itemAt(self, i):
raise NotImplementedError
def goToItem(self, item):
raise NotImplementedError
def serialize(self):
"""Serialize into an opaque format understood by self.deserialize."""
raise NotImplementedError

View File

@ -540,15 +540,16 @@ class CommandDispatcher:
else:
widget = self._current_widget()
for _ in range(count):
if forward:
if not widget.history.can_go_forward():
raise cmdexc.CommandError("At end of history.")
widget.history.forward()
else:
if not widget.history.can_go_back():
raise cmdexc.CommandError("At beginning of history.")
widget.history.back()
if forward:
try:
widget.history.forward(count)
except IndexError:
raise cmdexc.CommandError("At end of history.")
else:
try:
widget.history.back(count)
except IndexError:
raise cmdexc.CommandError("At beginning of history.")
@cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('count', count=True)

View File

@ -411,11 +411,21 @@ class WebEngineHistory(browsertab.AbstractHistory):
def current_idx(self):
return self._history.currentItemIndex()
def back(self):
self._history.back()
def back(self, count):
idx = self.current_idx() - count
if idx >= 0:
self.goToItem(self.itemAt(idx))
else:
self.goToItem(self.itemAt(0))
raise IndexError
def forward(self):
self._history.forward()
def forward(self, count):
idx = self.current_idx() + count
if idx < len(self):
self.goToItem(self.itemAt(idx))
else:
self.goToItem(self.itemAt(len(self) - 1))
raise IndexError
def can_go_back(self):
return self._history.canGoBack()
@ -423,6 +433,12 @@ class WebEngineHistory(browsertab.AbstractHistory):
def can_go_forward(self):
return self._history.canGoForward()
def itemAt(self, i):
return self._history.itemAt(i)
def goToItem(self, item):
return self._history.goToItem(item)
def serialize(self):
if not qtutils.version_check('5.9'):
# WORKAROUND for

View File

@ -506,11 +506,21 @@ class WebKitHistory(browsertab.AbstractHistory):
def current_idx(self):
return self._history.currentItemIndex()
def back(self):
self._history.back()
def back(self, count):
idx = self.current_idx() - count
if idx >= 0:
self.goToItem(self.itemAt(idx))
else:
self.goToItem(self.itemAt(0))
raise IndexError
def forward(self):
self._history.forward()
def forward(self, count):
idx = self.current_idx() + count
if idx < len(self):
self.goToItem(self.itemAt(idx))
else:
self.goToItem(self.itemAt(len(self) - 1))
raise IndexError
def can_go_back(self):
return self._history.canGoBack()
@ -518,6 +528,12 @@ class WebKitHistory(browsertab.AbstractHistory):
def can_go_forward(self):
return self._history.canGoForward()
def itemAt(self, i):
return self._history.itemAt(i)
def goToItem(self, item):
return self._history.goToItem(item)
def serialize(self):
return qtutils.serialize(self._history)