diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 2a9662eef..809c643c3 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -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 diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 3df4c288c..1f1b4f374 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -337,10 +337,7 @@ class WebEngineCaret(browsertab.AbstractCaret): return if js_elem == "focused": # we had a focused element, not a selected one. Just send - 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', diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py index 36da17dac..a9f4f9840 100644 --- a/qutebrowser/browser/webkit/webkittab.py +++ b/qutebrowser/browser/webkit/webkittab.py @@ -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(