Add :navigate up

This commit is contained in:
Florian Bruhin 2014-09-22 21:13:42 +02:00
parent 4615d22a5a
commit 4213550206
4 changed files with 22 additions and 6 deletions

View File

@ -71,7 +71,6 @@ Improvements / minor features
- Make sure commands in config are _complete_
- Config should check for unknown sections
- Print keybinding for command in completion [konubinix]
- "go up in the URL path" mapped to gu for example [egan]
- command which closes other tabs in a direction [egan]
- Distinction between :q and :wq, add ZZ and ZQ shortcuts.
- set_toggle to toggle setting between two states

View File

@ -15,7 +15,7 @@
|<<home,home>>|Open main startpage in current tab.
|<<inspector,inspector>>|Toggle the web inspector.
|<<later,later>>|Execute a command after some time.
|<<navigate,navigate>>|Open typical prev/next links.
|<<navigate,navigate>>|Open typical prev/next links or navigate using the URL path.
|<<open,open>>|Open a URL in the current/[count]th tab.
|<<paste,paste>>|Open a page from the clipboard.
|<<print,print>>|Print the current/[count]th tab.
@ -163,15 +163,16 @@ Execute a command after some time.
=== navigate
Syntax: +:navigate [*--tab*] 'where'+
Open typical prev/next links.
Open typical prev/next links or navigate using the URL path.
This tries to automatically click on typical _Previous Page_ or _Next Page_ links using some heuristics.
This tries to automatically click on typical _Previous Page_ or _Next Page_ links using some heuristics. Alternatively it can navigate by changing the current URL.
==== positional arguments
* +'where'+: What to open.
- `prev`: Open a _previous_ link.
- `next`: Open a _next_ link.
- `up`: Go up a level in the current URL.

View File

@ -21,6 +21,7 @@
import os
import subprocess
import posixpath
from functools import partial
from PyQt5.QtWidgets import QApplication
@ -299,17 +300,20 @@ class CommandDispatcher:
self._current_widget().hintmanager.follow_hint()
@cmdutils.register(instance='mainwindow.tabs.cmd')
def navigate(self, where : ('prev', 'next'), tab=False):
"""Open typical prev/next links.
def navigate(self, where: ('prev', 'next', 'up'), tab=False):
"""Open typical prev/next links or navigate using the URL path.
This tries to automatically click on typical _Previous Page_ or
_Next Page_ links using some heuristics.
Alternatively it can navigate by changing the current URL.
Args:
where: What to open.
- `prev`: Open a _previous_ link.
- `next`: Open a _next_ link.
- `up`: Go up a level in the current URL.
tab: Open in a new tab.
"""
@ -324,6 +328,16 @@ class CommandDispatcher:
elif where == 'next':
widget.hintmanager.follow_prevnext(frame, url, prev=False,
newtab=tab)
elif where == 'up':
path = url.path()
if not path or path == '/':
raise cmdexc.CommandError("Can't go up!")
new_path = posixpath.join(path, posixpath.pardir)
url.setPath(new_path)
if tab:
self._tabs.tabopen(url, background=False, explicit=True)
else:
widget.openurl(url)
else:
raise ValueError("Got called with invalid value {} for "
"`where'.".format(where))

View File

@ -931,6 +931,8 @@ KEY_DATA = collections.OrderedDict([
('navigate next', [']]']),
('navigate prev -t', ['{{']),
('navigate next -t', ['}}']),
('navigate up', ['gu']),
('navigate up -t', ['gU']),
('inspector', ['wi']),
('download-page', ['gd']),
('cancel-download', ['ad']),