Merge branch 'issue-401' of https://github.com/antoyo/qutebrowser into antoyo-issue-401

This commit is contained in:
Florian Bruhin 2015-05-31 19:46:17 +02:00
commit 4c8b1be19c
2 changed files with 37 additions and 0 deletions

View File

@ -25,7 +25,9 @@ import shlex
import subprocess import subprocess
import posixpath import posixpath
import functools import functools
import xml.etree.ElementTree
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWidgets import QApplication, QTabBar from PyQt5.QtWidgets import QApplication, QTabBar
from PyQt5.QtCore import Qt, QUrl, QEvent from PyQt5.QtCore import Qt, QUrl, QEvent
from PyQt5.QtGui import QClipboard, QKeyEvent from PyQt5.QtGui import QClipboard, QKeyEvent
@ -1007,6 +1009,39 @@ class CommandDispatcher:
url = objreg.get('quickmark-manager').get(name) url = objreg.get('quickmark-manager').get(name)
self._open(url, tab, bg, window) self._open(url, tab, bg, window)
@cmdutils.register(instance='command-dispatcher', hide=True,
scope='window')
def follow_selected(self, tab=False):
"""Follow the selected text.
Args:
tab: Load the selected link in a new tab.
"""
widget = self._current_widget()
page = widget.page()
if not page.hasSelection():
return
if QWebSettings.globalSettings().testAttribute(
QWebSettings.JavascriptEnabled):
if tab:
page.open_target = usertypes.ClickTarget.tab
page.currentFrame().evaluateJavaScript(
'window.getSelection().anchorNode.parentNode.click()')
else:
try:
selected_element = xml.etree.ElementTree.fromstring(
'<html>' + widget.selectedHtml() + '</html>').find('a')
except xml.etree.ElementTree.ParseError:
raise cmdexc.CommandError('Could not parse selected element!')
if selected_element is not None:
try:
url = selected_element.attrib['href']
except KeyError:
raise cmdexc.CommandError('Anchor element without href!')
url = self._current_url().resolved(QUrl(url))
self._open(url, tab)
@cmdutils.register(instance='command-dispatcher', name='inspector', @cmdutils.register(instance='command-dispatcher', name='inspector',
scope='window') scope='window')
def toggle_inspector(self): def toggle_inspector(self):

View File

@ -1239,6 +1239,8 @@ KEY_DATA = collections.OrderedDict([
('stop', ['<Ctrl-s>']), ('stop', ['<Ctrl-s>']),
('print', ['<Ctrl-Alt-p>']), ('print', ['<Ctrl-Alt-p>']),
('open qute:settings', ['Ss']), ('open qute:settings', ['Ss']),
('follow-selected', ['<Return>']),
('follow-selected -t', ['<Ctrl-Return>']),
])), ])),
('insert', collections.OrderedDict([ ('insert', collections.OrderedDict([