Merge branch 'antoyo-issue-401'
This commit is contained in:
commit
9cece08b2b
@ -139,6 +139,7 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* Joel Torstensson
|
* Joel Torstensson
|
||||||
* Claude
|
* Claude
|
||||||
* Artur Shaik
|
* Artur Shaik
|
||||||
|
* Antoni Boucher
|
||||||
* ZDarian
|
* ZDarian
|
||||||
* Peter Vilim
|
* Peter Vilim
|
||||||
* Martin Tournoij
|
* Martin Tournoij
|
||||||
|
@ -692,6 +692,7 @@ How many steps to zoom out.
|
|||||||
|<<drop-selection,drop-selection>>|Drop selection and keep selection mode enabled.
|
|<<drop-selection,drop-selection>>|Drop selection and keep selection mode enabled.
|
||||||
|<<enter-mode,enter-mode>>|Enter a key mode.
|
|<<enter-mode,enter-mode>>|Enter a key mode.
|
||||||
|<<follow-hint,follow-hint>>|Follow the currently selected hint.
|
|<<follow-hint,follow-hint>>|Follow the currently selected hint.
|
||||||
|
|<<follow-selected,follow-selected>>|Follow the selected text.
|
||||||
|<<leave-mode,leave-mode>>|Leave the mode we're currently in.
|
|<<leave-mode,leave-mode>>|Leave the mode we're currently in.
|
||||||
|<<message-error,message-error>>|Show an error message in the statusbar.
|
|<<message-error,message-error>>|Show an error message in the statusbar.
|
||||||
|<<message-info,message-info>>|Show an info message in the statusbar.
|
|<<message-info,message-info>>|Show an info message in the statusbar.
|
||||||
@ -774,6 +775,15 @@ Enter a key mode.
|
|||||||
=== follow-hint
|
=== follow-hint
|
||||||
Follow the currently selected hint.
|
Follow the currently selected hint.
|
||||||
|
|
||||||
|
[[follow-selected]]
|
||||||
|
=== follow-selected
|
||||||
|
Syntax: +:follow-selected [*--tab*]+
|
||||||
|
|
||||||
|
Follow the selected text.
|
||||||
|
|
||||||
|
==== optional arguments
|
||||||
|
* +*-t*+, +*--tab*+: Load the selected link in a new tab.
|
||||||
|
|
||||||
[[leave-mode]]
|
[[leave-mode]]
|
||||||
=== leave-mode
|
=== leave-mode
|
||||||
Leave the mode we're currently in.
|
Leave the mode we're currently in.
|
||||||
|
@ -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):
|
||||||
|
@ -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([
|
||||||
|
Loading…
Reference in New Issue
Block a user