diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 2964b6113..5438b29a0 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -482,7 +482,8 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('where', choices=['prev', 'next', 'up', 'increment', 'decrement']) - def navigate(self, where: str, tab=False, bg=False, window=False): + @cmdutils.argument('count', count=True) + def navigate(self, where: str, tab=False, bg=False, window=False, count=1): """Open typical prev/next links or navigate using the URL path. This tries to automatically click on typical _Previous Page_ or @@ -526,7 +527,7 @@ class CommandDispatcher: handler(browsertab=widget, win_id=self._win_id, baseurl=url, tab=tab, background=bg, window=window) elif where in ['up', 'increment', 'decrement']: - new_url = handlers[where](url) + new_url = handlers[where](url, count) self._open(new_url, tab, bg, window) else: # pragma: no cover raise ValueError("Got called with invalid value {} for " diff --git a/qutebrowser/browser/navigate.py b/qutebrowser/browser/navigate.py index 86e7eeb77..2d5b0aab3 100644 --- a/qutebrowser/browser/navigate.py +++ b/qutebrowser/browser/navigate.py @@ -31,7 +31,7 @@ class Error(Exception): """Raised when the navigation can't be done.""" -def incdec(url, inc_or_dec): +def incdec(url, count, inc_or_dec): """Helper method for :navigate when `where' is increment/decrement. Args: @@ -43,13 +43,13 @@ def incdec(url, inc_or_dec): """ segments = set(config.get('general', 'url-incdec-segments')) try: - new_url = urlutils.incdec_number(url, inc_or_dec, segments=segments) + new_url = urlutils.incdec_number(url, inc_or_dec, count, segments=segments) except urlutils.IncDecError as error: raise Error(error.msg) return new_url -def path_up(url): +def path_up(url, count): """Helper method for :navigate when `where' is up. Args: @@ -58,8 +58,9 @@ def path_up(url): path = url.path() if not path or path == '/': raise Error("Can't go up!") - new_path = posixpath.join(path, posixpath.pardir) - url.setPath(new_path) + for i in range(0, min(count, path.count('/'))): + path = posixpath.join(path, posixpath.pardir) + url.setPath(path) return url diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index 2fe465aa4..d37a2772e 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -499,7 +499,7 @@ class IncDecError(Exception): return '{}: {}'.format(self.msg, self.url.toString()) -def _get_incdec_value(match, incdec, url): +def _get_incdec_value(match, incdec, url, count): """Get an incremented/decremented URL based on a URL match.""" pre, zeroes, number, post = match.groups() # This should always succeed because we match \d+ @@ -507,9 +507,9 @@ def _get_incdec_value(match, incdec, url): if incdec == 'decrement': if val <= 0: raise IncDecError("Can't decrement {}!".format(val), url) - val -= 1 + val -= count elif incdec == 'increment': - val += 1 + val += count else: raise ValueError("Invalid value {} for indec!".format(incdec)) if zeroes: @@ -521,7 +521,7 @@ def _get_incdec_value(match, incdec, url): return ''.join([pre, zeroes, str(val), post]) -def incdec_number(url, incdec, segments=None): +def incdec_number(url, incdec, count=1, segments=None): """Find a number in the url and increment or decrement it. Args: @@ -566,7 +566,7 @@ def incdec_number(url, incdec, segments=None): if not match: continue - setter(_get_incdec_value(match, incdec, url)) + setter(_get_incdec_value(match, incdec, url, count)) return url raise IncDecError("No number found in URL!", url)