Skip intermediate pages with :back/:forward and a count
This commit is contained in:
parent
0e8175b8eb
commit
c6ed4fe4f9
@ -477,6 +477,12 @@ class AbstractHistory:
|
|||||||
def can_go_forward(self):
|
def can_go_forward(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def itemAt(self, i):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def goToItem(self, item):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
"""Serialize into an opaque format understood by self.deserialize."""
|
"""Serialize into an opaque format understood by self.deserialize."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -540,15 +540,16 @@ class CommandDispatcher:
|
|||||||
else:
|
else:
|
||||||
widget = self._current_widget()
|
widget = self._current_widget()
|
||||||
|
|
||||||
for _ in range(count):
|
if forward:
|
||||||
if forward:
|
try:
|
||||||
if not widget.history.can_go_forward():
|
widget.history.forward(count)
|
||||||
raise cmdexc.CommandError("At end of history.")
|
except IndexError:
|
||||||
widget.history.forward()
|
raise cmdexc.CommandError("At end of history.")
|
||||||
else:
|
else:
|
||||||
if not widget.history.can_go_back():
|
try:
|
||||||
raise cmdexc.CommandError("At beginning of history.")
|
widget.history.back(count)
|
||||||
widget.history.back()
|
except IndexError:
|
||||||
|
raise cmdexc.CommandError("At beginning of history.")
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
@cmdutils.argument('count', count=True)
|
@cmdutils.argument('count', count=True)
|
||||||
|
@ -411,11 +411,21 @@ class WebEngineHistory(browsertab.AbstractHistory):
|
|||||||
def current_idx(self):
|
def current_idx(self):
|
||||||
return self._history.currentItemIndex()
|
return self._history.currentItemIndex()
|
||||||
|
|
||||||
def back(self):
|
def back(self, count):
|
||||||
self._history.back()
|
idx = self.current_idx() - count
|
||||||
|
if idx >= 0:
|
||||||
|
self.goToItem(self.itemAt(idx))
|
||||||
|
else:
|
||||||
|
self.goToItem(self.itemAt(0))
|
||||||
|
raise IndexError
|
||||||
|
|
||||||
def forward(self):
|
def forward(self, count):
|
||||||
self._history.forward()
|
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):
|
def can_go_back(self):
|
||||||
return self._history.canGoBack()
|
return self._history.canGoBack()
|
||||||
@ -423,6 +433,12 @@ class WebEngineHistory(browsertab.AbstractHistory):
|
|||||||
def can_go_forward(self):
|
def can_go_forward(self):
|
||||||
return self._history.canGoForward()
|
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):
|
def serialize(self):
|
||||||
if not qtutils.version_check('5.9'):
|
if not qtutils.version_check('5.9'):
|
||||||
# WORKAROUND for
|
# WORKAROUND for
|
||||||
|
@ -506,11 +506,21 @@ class WebKitHistory(browsertab.AbstractHistory):
|
|||||||
def current_idx(self):
|
def current_idx(self):
|
||||||
return self._history.currentItemIndex()
|
return self._history.currentItemIndex()
|
||||||
|
|
||||||
def back(self):
|
def back(self, count):
|
||||||
self._history.back()
|
idx = self.current_idx() - count
|
||||||
|
if idx >= 0:
|
||||||
|
self.goToItem(self.itemAt(idx))
|
||||||
|
else:
|
||||||
|
self.goToItem(self.itemAt(0))
|
||||||
|
raise IndexError
|
||||||
|
|
||||||
def forward(self):
|
def forward(self, count):
|
||||||
self._history.forward()
|
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):
|
def can_go_back(self):
|
||||||
return self._history.canGoBack()
|
return self._history.canGoBack()
|
||||||
@ -518,6 +528,12 @@ class WebKitHistory(browsertab.AbstractHistory):
|
|||||||
def can_go_forward(self):
|
def can_go_forward(self):
|
||||||
return self._history.canGoForward()
|
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):
|
def serialize(self):
|
||||||
return qtutils.serialize(self._history)
|
return qtutils.serialize(self._history)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user