Simplify selection handling and remove QUTE_SELECTED_HTML

It was broken at least since caret support was introduced and it was only
available for QtWebKit anyways, so let's just drop it. This also makes the tab
API a bit simpler.
This commit is contained in:
Florian Bruhin 2018-02-06 22:48:00 +01:00
parent 16375f20d5
commit ce8d15d2b0
6 changed files with 14 additions and 24 deletions

View File

@ -55,6 +55,12 @@ Fixed
- `:bookmark-add "" foo` can now be used to save the current URL with a custom
title.
Removed
~~~~~~~
- `QUTE_SELECTED_HTML` is now not set for userscripts anymore except when called
via hints.
v1.1.1
------

View File

@ -45,8 +45,6 @@ In `command` mode:
- `QUTE_URL`: The current URL.
- `QUTE_TITLE`: The title of the current page.
- `QUTE_SELECTED_TEXT`: The text currently selected on the page.
- `QUTE_SELECTED_HTML` The HTML currently selected on the page (not supported
with QtWebEngine).
In `hints` mode:

View File

@ -392,7 +392,7 @@ class AbstractCaret(QObject):
def drop_selection(self):
raise NotImplementedError
def selection(self, html=False, callback=None):
def selection(self, callback=None):
raise NotImplementedError
def follow_selected(self, *, tab=False):

View File

@ -1260,21 +1260,15 @@ class CommandDispatcher:
"""
env = {
'QUTE_MODE': 'command',
'QUTE_SELECTED_TEXT': selection,
}
idx = self._current_index()
if idx != -1:
env['QUTE_TITLE'] = self._tabbed_browser.page_title(idx)
tab = self._tabbed_browser.currentWidget()
if tab is not None:
env['QUTE_SELECTED_TEXT'] = selection
try:
env['QUTE_SELECTED_HTML'] = tab.caret.selection(html=True)
except browsertab.UnsupportedOperationError:
pass
# FIXME:qtwebengine: If tab is None, run_async will fail!
tab = self._tabbed_browser.currentWidget()
try:
url = self._tabbed_browser.current_url()

View File

@ -289,9 +289,7 @@ class WebEngineCaret(browsertab.AbstractCaret):
def drop_selection(self):
self._js_call('dropSelection')
def selection(self, html=False, callback=None):
if html:
raise browsertab.UnsupportedOperationError
def selection(self, callback=None):
# Not using selectedText() as WORKAROUND for
# https://bugreports.qt.io/browse/QTBUG-53134
# Even on Qt 5.10 selectedText() seems to work poorly, see

View File

@ -188,7 +188,7 @@ class WebKitCaret(browsertab.AbstractCaret):
settings = self._widget.settings()
settings.setAttribute(QWebSettings.CaretBrowsingEnabled, True)
self.selection_enabled = bool(self._selection())
self.selection_enabled = self._widget.hasSelection()
if self._widget.isVisible():
# Sometimes the caret isn't immediately visible, but unfocusing
@ -360,14 +360,8 @@ class WebKitCaret(browsertab.AbstractCaret):
def drop_selection(self):
self._widget.triggerPageAction(QWebPage.MoveToNextChar)
def selection(self, html=False, callback=False):
callback(self._selection(html))
def _selection(self, html=False):
if html:
return self._widget.selectedHtml()
else:
return self._widget.selectedText()
def selection(self, callback):
callback(self._widget.selectedText())
def follow_selected(self, *, tab=False):
if QWebSettings.globalSettings().testAttribute(
@ -377,7 +371,7 @@ class WebKitCaret(browsertab.AbstractCaret):
self._tab.run_js_async(
'window.getSelection().anchorNode.parentNode.click()')
else:
selection = self._selection(html=True)
selection = self._widget.selectedHtml()
if not selection:
return
try: