Move pressing Enter into a method
This commit is contained in:
parent
7f69920158
commit
cf8dbd8bfd
@ -414,6 +414,13 @@ class AbstractCaret(QObject):
|
|||||||
def selection(self, callback):
|
def selection(self, callback):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def _follow_enter(self, tab):
|
||||||
|
"""Follow a link by faking an enter press."""
|
||||||
|
if tab:
|
||||||
|
self._tab.key_press(Qt.Key_Enter, modifier=Qt.ControlModifier)
|
||||||
|
else:
|
||||||
|
self._tab.key_press(Qt.Key_Enter)
|
||||||
|
|
||||||
def follow_selected(self, *, tab=False):
|
def follow_selected(self, *, tab=False):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -337,10 +337,7 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
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>
|
||||||
if tab:
|
self._follow_enter(tab)
|
||||||
self._tab.key_press(Qt.Key_Enter, modifier=Qt.ControlModifier)
|
|
||||||
else:
|
|
||||||
self._tab.key_press(Qt.Key_Enter)
|
|
||||||
|
|
||||||
assert isinstance(js_elem, dict), js_elem
|
assert isinstance(js_elem, dict), js_elem
|
||||||
elem = webengineelem.WebEngineElement(js_elem, tab=self._tab)
|
elem = webengineelem.WebEngineElement(js_elem, tab=self._tab)
|
||||||
@ -364,11 +361,7 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
|||||||
|
|
||||||
log.webview.debug("Clicking a searched link via fake key press.")
|
log.webview.debug("Clicking a searched link via fake key press.")
|
||||||
# send a fake enter, clicking the orange selection box
|
# send a fake enter, clicking the orange selection box
|
||||||
if tab:
|
self._follow_enter(tab)
|
||||||
self._tab.key_press(Qt.Key_Enter, modifier=Qt.ControlModifier)
|
|
||||||
else:
|
|
||||||
self._tab.key_press(Qt.Key_Enter)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# click an existing blue selection
|
# click an existing blue selection
|
||||||
js_code = javascript.assemble('webelem',
|
js_code = javascript.assemble('webelem',
|
||||||
|
@ -392,11 +392,7 @@ class WebKitCaret(browsertab.AbstractCaret):
|
|||||||
# about that until this commit is released:
|
# about that until this commit is released:
|
||||||
# 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
|
||||||
if tab:
|
self._follow_enter(tab)
|
||||||
self._tab.key_press(Qt.Key_Enter,
|
|
||||||
modifier=Qt.ControlModifier)
|
|
||||||
else:
|
|
||||||
self._tab.key_press(Qt.Key_Enter)
|
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
selected_element = xml.etree.ElementTree.fromstring(
|
selected_element = xml.etree.ElementTree.fromstring(
|
||||||
|
Loading…
Reference in New Issue
Block a user