Clean up emitting of follow_selected_done
This commit is contained in:
parent
9edbcfb828
commit
59413810bf
@ -335,7 +335,13 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
self._tab.run_js_async(javascript.assemble('caret', 'getSelection'),
|
self._tab.run_js_async(javascript.assemble('caret', 'getSelection'),
|
||||||
callback)
|
callback)
|
||||||
|
|
||||||
def _follow_selected_cb(self, js_elem, tab=False):
|
def _follow_selected_cb_wrapped(self, js_elem, tab):
|
||||||
|
try:
|
||||||
|
self._follow_selected_cb(js_elem, tab)
|
||||||
|
finally:
|
||||||
|
self.follow_selected_done.emit()
|
||||||
|
|
||||||
|
def _follow_selected_cb(self, js_elem, tab):
|
||||||
"""Callback for javascript which clicks the selected element.
|
"""Callback for javascript which clicks the selected element.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -343,13 +349,11 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
tab: Open in a new tab.
|
tab: Open in a new tab.
|
||||||
"""
|
"""
|
||||||
if js_elem is None:
|
if js_elem is None:
|
||||||
self.follow_selected_done.emit()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if js_elem == "focused":
|
if js_elem == "focused":
|
||||||
# we had a focused element, not a selected one. Just send <enter>
|
# we had a focused element, not a selected one. Just send <enter>
|
||||||
self._follow_enter(tab)
|
self._follow_enter(tab)
|
||||||
self.follow_selected_done.emit()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
assert isinstance(js_elem, dict), js_elem
|
assert isinstance(js_elem, dict), js_elem
|
||||||
@ -368,8 +372,6 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
except webelem.Error as e:
|
except webelem.Error as e:
|
||||||
message.error(str(e))
|
message.error(str(e))
|
||||||
|
|
||||||
self.follow_selected_done.emit()
|
|
||||||
|
|
||||||
def follow_selected(self, *, tab=False):
|
def follow_selected(self, *, tab=False):
|
||||||
if self._tab.search.search_displayed:
|
if self._tab.search.search_displayed:
|
||||||
# We are currently in search mode.
|
# We are currently in search mode.
|
||||||
@ -384,8 +386,9 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
# click an existing blue selection
|
# click an existing blue selection
|
||||||
js_code = javascript.assemble('webelem',
|
js_code = javascript.assemble('webelem',
|
||||||
'find_selected_focused_link')
|
'find_selected_focused_link')
|
||||||
self._tab.run_js_async(js_code, lambda jsret:
|
self._tab.run_js_async(
|
||||||
self._follow_selected_cb(jsret, tab))
|
js_code,
|
||||||
|
lambda jsret: self._follow_selected_cb_wrapped(jsret, tab))
|
||||||
|
|
||||||
def _js_call(self, command, *args, callback=None):
|
def _js_call(self, command, *args, callback=None):
|
||||||
code = javascript.assemble('caret', command, *args)
|
code = javascript.assemble('caret', command, *args)
|
||||||
|
@ -348,7 +348,7 @@ class WebKitCaret(browsertab.AbstractCaret):
|
|||||||
def selection(self, callback):
|
def selection(self, callback):
|
||||||
callback(self._widget.selectedText())
|
callback(self._widget.selectedText())
|
||||||
|
|
||||||
def follow_selected(self, *, tab=False):
|
def _follow_selected(self, *, tab=False):
|
||||||
if QWebSettings.globalSettings().testAttribute(
|
if QWebSettings.globalSettings().testAttribute(
|
||||||
QWebSettings.JavascriptEnabled):
|
QWebSettings.JavascriptEnabled):
|
||||||
if tab:
|
if tab:
|
||||||
@ -369,13 +369,11 @@ class WebKitCaret(browsertab.AbstractCaret):
|
|||||||
# https://github.com/annulen/webkit/commit/0e75f3272d149bc64899c161f150eb341a2417af
|
# https://github.com/annulen/webkit/commit/0e75f3272d149bc64899c161f150eb341a2417af
|
||||||
# TODO find a way to check if something is focused
|
# TODO find a way to check if something is focused
|
||||||
self._follow_enter(tab)
|
self._follow_enter(tab)
|
||||||
self.follow_selected_done.emit()
|
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
selected_element = xml.etree.ElementTree.fromstring(
|
selected_element = xml.etree.ElementTree.fromstring(
|
||||||
'<html>{}</html>'.format(selection)).find('a')
|
'<html>{}</html>'.format(selection)).find('a')
|
||||||
except xml.etree.ElementTree.ParseError:
|
except xml.etree.ElementTree.ParseError:
|
||||||
self.follow_selected_done.emit()
|
|
||||||
raise browsertab.WebTabError('Could not parse selected '
|
raise browsertab.WebTabError('Could not parse selected '
|
||||||
'element!')
|
'element!')
|
||||||
|
|
||||||
@ -383,7 +381,6 @@ class WebKitCaret(browsertab.AbstractCaret):
|
|||||||
try:
|
try:
|
||||||
url = selected_element.attrib['href']
|
url = selected_element.attrib['href']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.follow_selected_done.emit()
|
|
||||||
raise browsertab.WebTabError('Anchor element without '
|
raise browsertab.WebTabError('Anchor element without '
|
||||||
'href!')
|
'href!')
|
||||||
url = self._tab.url().resolved(QUrl(url))
|
url = self._tab.url().resolved(QUrl(url))
|
||||||
@ -392,7 +389,11 @@ class WebKitCaret(browsertab.AbstractCaret):
|
|||||||
else:
|
else:
|
||||||
self._tab.openurl(url)
|
self._tab.openurl(url)
|
||||||
|
|
||||||
self.follow_selected_done.emit()
|
def follow_selected(self, *, tab=False):
|
||||||
|
try:
|
||||||
|
self._follow_selected(tab=tab)
|
||||||
|
finally:
|
||||||
|
self.follow_selected_done.emit()
|
||||||
|
|
||||||
|
|
||||||
class WebKitZoom(browsertab.AbstractZoom):
|
class WebKitZoom(browsertab.AbstractZoom):
|
||||||
|
Loading…
Reference in New Issue
Block a user