QtWebEngine: Fix crash with userscript + selection

Fixes #1878

Unfortunately it seems impossible to implement a test for this, as
selection via javascript somehow doesn't trigger this.
This commit is contained in:
Florian Bruhin 2016-09-01 22:45:14 +02:00
parent d8492fef61
commit 44d6db4f45
4 changed files with 12 additions and 3 deletions

View File

@ -42,7 +42,8 @@ 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.
- `QUTE_SELECTED_HTML` The HTML currently selected on the page (not supported
with QtWebEngine).
In `hints` mode:

View File

@ -60,6 +60,11 @@ class WebTabError(Exception):
"""Base class for various errors."""
class UnsupportedOperationError(WebTabError):
"""Raised when an operation is not supported with the given backend."""
class TabData:
"""A simple namespace with a fixed set of attributes.

View File

@ -1089,7 +1089,10 @@ class CommandDispatcher:
tab = self._tabbed_browser.currentWidget()
if tab is not None and tab.caret.has_selection():
env['QUTE_SELECTED_TEXT'] = tab.caret.selection()
env['QUTE_SELECTED_HTML'] = tab.caret.selection(html=True)
try:
env['QUTE_SELECTED_HTML'] = tab.caret.selection(html=True)
except browsertab.UnsupportedOperationError:
pass
# FIXME:qtwebengine: If tab is None, run_async will fail!

View File

@ -171,7 +171,7 @@ class WebEngineCaret(browsertab.AbstractCaret):
def selection(self, html=False):
if html:
raise NotImplementedError
raise browsertab.UnsupportedOperationError
return self._widget.selectedText()
def follow_selected(self, *, tab=False):