Add increment/decrement to :navigate
This commit is contained in:
parent
4213550206
commit
207bb00c50
1
doc/TODO
1
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:
|
||||
|
@ -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.
|
||||
|
||||
|
||||
|
||||
|
@ -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))
|
||||
|
@ -933,6 +933,8 @@ KEY_DATA = collections.OrderedDict([
|
||||
('navigate next -t', ['}}']),
|
||||
('navigate up', ['gu']),
|
||||
('navigate up -t', ['gU']),
|
||||
('navigate increment', ['<Ctrl-A>']),
|
||||
('navigate decrement', ['<Ctrl-X>']),
|
||||
('inspector', ['wi']),
|
||||
('download-page', ['gd']),
|
||||
('cancel-download', ['ad']),
|
||||
|
Loading…
Reference in New Issue
Block a user