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):
|
||||
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):
|
||||
raise NotImplementedError
|
||||
|
||||
|
@ -337,10 +337,7 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
||||
return
|
||||
if js_elem == "focused":
|
||||
# we had a focused element, not a selected one. Just send <enter>
|
||||
if tab:
|
||||
self._tab.key_press(Qt.Key_Enter, modifier=Qt.ControlModifier)
|
||||
else:
|
||||
self._tab.key_press(Qt.Key_Enter)
|
||||
self._follow_enter(tab)
|
||||
|
||||
assert isinstance(js_elem, dict), js_elem
|
||||
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.")
|
||||
# send a fake enter, clicking the orange selection box
|
||||
if tab:
|
||||
self._tab.key_press(Qt.Key_Enter, modifier=Qt.ControlModifier)
|
||||
else:
|
||||
self._tab.key_press(Qt.Key_Enter)
|
||||
|
||||
self._follow_enter(tab)
|
||||
else:
|
||||
# click an existing blue selection
|
||||
js_code = javascript.assemble('webelem',
|
||||
|
@ -392,11 +392,7 @@ class WebKitCaret(browsertab.AbstractCaret):
|
||||
# about that until this commit is released:
|
||||
# https://github.com/annulen/webkit/commit/0e75f3272d149bc64899c161f150eb341a2417af
|
||||
# TODO find a way to check if something is focused
|
||||
if tab:
|
||||
self._tab.key_press(Qt.Key_Enter,
|
||||
modifier=Qt.ControlModifier)
|
||||
else:
|
||||
self._tab.key_press(Qt.Key_Enter)
|
||||
self._follow_enter(tab)
|
||||
return
|
||||
try:
|
||||
selected_element = xml.etree.ElementTree.fromstring(
|
||||
|
Loading…
Reference in New Issue
Block a user