Simplify :navigate command

This commit is contained in:
Florian Bruhin 2020-08-03 16:14:41 +02:00
parent 30a0fdfc10
commit 32c95b5abe
2 changed files with 9 additions and 6 deletions

View File

@ -614,14 +614,9 @@ class CommandDispatcher:
handler = handlers[where]
handler(browsertab=widget, win_id=self._win_id, baseurl=url,
tab=tab, background=bg, window=window)
elif where in ['up', 'increment', 'decrement']:
if where == 'up':
url = url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery)
elif where in ['up', 'increment', 'decrement', 'strip']:
new_url = handlers[where](url, count)
self._open(new_url, tab, bg, window, related=True)
elif where == 'strip':
url = url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery)
self._open(url, tab, bg, window, related=True)
else: # pragma: no cover
raise ValueError("Got called with invalid value {} for "
"`where'.".format(where))

View File

@ -132,6 +132,7 @@ def path_up(url, count):
url: The current url.
count: The number of levels to go up in the url.
"""
url = url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery)
path = url.path()
if not path or path == '/':
raise Error("Can't go up!")
@ -142,6 +143,13 @@ def path_up(url, count):
return url
def strip(url, count):
"""Strip fragment/query from a URL."""
if count != 1:
raise Error("Count is not supported when stripping URL components")
return url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery)
def _find_prevnext(prev, elems):
"""Find a prev/next element in the given list of elements."""
# First check for <link rel="prev(ious)|next">