From 207bb00c50958e7e710fe3a02dfdbd83e14ec72a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 22 Sep 2014 21:51:09 +0200 Subject: [PATCH] Add increment/decrement to :navigate --- doc/TODO | 1 - doc/help/commands.asciidoc | 2 ++ qutebrowser/browser/commands.py | 33 +++++++++++++++++++++++++++++++- qutebrowser/config/configdata.py | 2 ++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/doc/TODO b/doc/TODO index fc075f2cd..1b19d56cf 100644 --- a/doc/TODO +++ b/doc/TODO @@ -94,7 +94,6 @@ Improvements / minor features - clear cookies command - keybind/aliases should have completion for commands/arguments - Hiding scrollbars -- Ctrl+A/X to increase/decrease last number in URL - Add more element-selection-detection code (with options?) (see notes) - somehow unfocus elements (hide blinking cursor) when insert mode is left? - Copy link location on crash mail should not copy mailto: diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index cc96558dc..3b6b40820 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -173,6 +173,8 @@ This tries to automatically click on typical _Previous Page_ or _Next Page_ link - `prev`: Open a _previous_ link. - `next`: Open a _next_ link. - `up`: Go up a level in the current URL. + - `increment`: Increment the last number in the URL. + - `decrement`: Decrement the last number in the URL. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 17987b435..1c016ca37 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -19,6 +19,7 @@ """Command dispatcher for TabbedBrowser.""" +import re import os import subprocess import posixpath @@ -300,7 +301,8 @@ class CommandDispatcher: self._current_widget().hintmanager.follow_hint() @cmdutils.register(instance='mainwindow.tabs.cmd') - def navigate(self, where: ('prev', 'next', 'up'), tab=False): + def navigate(self, where: ('prev', 'next', 'up', 'increment', 'decrement'), + tab=False): """Open typical prev/next links or navigate using the URL path. This tries to automatically click on typical _Previous Page_ or @@ -314,6 +316,8 @@ class CommandDispatcher: - `prev`: Open a _previous_ link. - `next`: Open a _next_ link. - `up`: Go up a level in the current URL. + - `increment`: Increment the last number in the URL. + - `decrement`: Decrement the last number in the URL. tab: Open in a new tab. """ @@ -338,6 +342,33 @@ class CommandDispatcher: self._tabs.tabopen(url, background=False, explicit=True) else: widget.openurl(url) + elif where in ('decrement', 'increment'): + encoded = bytes(url.toEncoded()).decode('ascii') + # Get the last number in a string + match = re.match(r'(.*\D|^)(\d+)(.*)', encoded) + if not match: + raise cmdexc.CommandError("No number found in URL!") + pre, number, post = match.groups() + if not number: + raise cmdexc.CommandError("No number found in URL!") + try: + val = int(number) + except ValueError: + raise cmdexc.CommandError( + "Could not parse number '{}'.".format(number)) + if where == 'decrement': + if val <= 0: + raise cmdexc.CommandError("Can't decrement {}!".format( + val)) + val -= 1 + else: + val += 1 + urlstr = ''.join([pre, str(val), post]).encode('ascii') + new_url = QUrl.fromEncoded(urlstr) + if tab: + self._tabs.tabopen(new_url, background=False, explicit=True) + else: + widget.openurl(new_url) else: raise ValueError("Got called with invalid value {} for " "`where'.".format(where)) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index df24c2f0b..fa9b43365 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -933,6 +933,8 @@ KEY_DATA = collections.OrderedDict([ ('navigate next -t', ['}}']), ('navigate up', ['gu']), ('navigate up -t', ['gU']), + ('navigate increment', ['']), + ('navigate decrement', ['']), ('inspector', ['wi']), ('download-page', ['gd']), ('cancel-download', ['ad']),