Add increment/decrement to :navigate

This commit is contained in:
Florian Bruhin 2014-09-22 21:51:09 +02:00
parent 4213550206
commit 207bb00c50
4 changed files with 36 additions and 2 deletions

View File

@ -94,7 +94,6 @@ Improvements / minor features
- clear cookies command - clear cookies command
- keybind/aliases should have completion for commands/arguments - keybind/aliases should have completion for commands/arguments
- Hiding scrollbars - Hiding scrollbars
- Ctrl+A/X to increase/decrease last number in URL
- Add more element-selection-detection code (with options?) (see notes) - Add more element-selection-detection code (with options?) (see notes)
- somehow unfocus elements (hide blinking cursor) when insert mode is left? - somehow unfocus elements (hide blinking cursor) when insert mode is left?
- Copy link location on crash mail should not copy mailto: - Copy link location on crash mail should not copy mailto:

View File

@ -173,6 +173,8 @@ This tries to automatically click on typical _Previous Page_ or _Next Page_ link
- `prev`: Open a _previous_ link. - `prev`: Open a _previous_ link.
- `next`: Open a _next_ link. - `next`: Open a _next_ link.
- `up`: Go up a level in the current URL. - `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.

View File

@ -19,6 +19,7 @@
"""Command dispatcher for TabbedBrowser.""" """Command dispatcher for TabbedBrowser."""
import re
import os import os
import subprocess import subprocess
import posixpath import posixpath
@ -300,7 +301,8 @@ class CommandDispatcher:
self._current_widget().hintmanager.follow_hint() self._current_widget().hintmanager.follow_hint()
@cmdutils.register(instance='mainwindow.tabs.cmd') @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. """Open typical prev/next links or navigate using the URL path.
This tries to automatically click on typical _Previous Page_ or This tries to automatically click on typical _Previous Page_ or
@ -314,6 +316,8 @@ class CommandDispatcher:
- `prev`: Open a _previous_ link. - `prev`: Open a _previous_ link.
- `next`: Open a _next_ link. - `next`: Open a _next_ link.
- `up`: Go up a level in the current URL. - `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. tab: Open in a new tab.
""" """
@ -338,6 +342,33 @@ class CommandDispatcher:
self._tabs.tabopen(url, background=False, explicit=True) self._tabs.tabopen(url, background=False, explicit=True)
else: else:
widget.openurl(url) 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: else:
raise ValueError("Got called with invalid value {} for " raise ValueError("Got called with invalid value {} for "
"`where'.".format(where)) "`where'.".format(where))

View File

@ -933,6 +933,8 @@ KEY_DATA = collections.OrderedDict([
('navigate next -t', ['}}']), ('navigate next -t', ['}}']),
('navigate up', ['gu']), ('navigate up', ['gu']),
('navigate up -t', ['gU']), ('navigate up -t', ['gU']),
('navigate increment', ['<Ctrl-A>']),
('navigate decrement', ['<Ctrl-X>']),
('inspector', ['wi']), ('inspector', ['wi']),
('download-page', ['gd']), ('download-page', ['gd']),
('cancel-download', ['ad']), ('cancel-download', ['ad']),