Revert "Revert "Make sure we wait until follow_selected is done""
This reverts commit 200c11625f
.
This commit is contained in:
parent
200c11625f
commit
4ae78d9bb2
@ -395,9 +395,11 @@ class AbstractCaret(QObject):
|
||||
Signals:
|
||||
selection_toggled: Emitted when the selection was toggled.
|
||||
arg: Whether the selection is now active.
|
||||
follow_selected_done: Emitted when a follow_selection action is done.
|
||||
"""
|
||||
|
||||
selection_toggled = pyqtSignal(bool)
|
||||
follow_selected_done = pyqtSignal()
|
||||
|
||||
def __init__(self, tab, mode_manager, parent=None):
|
||||
super().__init__(parent)
|
||||
|
@ -344,10 +344,13 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
||||
tab: Open in a new tab.
|
||||
"""
|
||||
if js_elem is None:
|
||||
self.follow_selected_done.emit()
|
||||
return
|
||||
|
||||
if js_elem == "focused":
|
||||
# we had a focused element, not a selected one. Just send <enter>
|
||||
self._follow_enter(tab)
|
||||
self.follow_selected_done.emit()
|
||||
return
|
||||
|
||||
assert isinstance(js_elem, dict), js_elem
|
||||
@ -365,7 +368,8 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
||||
elem.click(click_type)
|
||||
except webelem.Error as e:
|
||||
message.error(str(e))
|
||||
return
|
||||
|
||||
self.follow_selected_done.emit()
|
||||
|
||||
def follow_selected(self, *, tab=False):
|
||||
if self._tab.search.search_displayed:
|
||||
|
@ -369,11 +369,13 @@ class WebKitCaret(browsertab.AbstractCaret):
|
||||
# https://github.com/annulen/webkit/commit/0e75f3272d149bc64899c161f150eb341a2417af
|
||||
# TODO find a way to check if something is focused
|
||||
self._follow_enter(tab)
|
||||
self.follow_selected_done.emit()
|
||||
return
|
||||
try:
|
||||
selected_element = xml.etree.ElementTree.fromstring(
|
||||
'<html>{}</html>'.format(selection)).find('a')
|
||||
except xml.etree.ElementTree.ParseError:
|
||||
self.follow_selected_done.emit()
|
||||
raise browsertab.WebTabError('Could not parse selected '
|
||||
'element!')
|
||||
|
||||
@ -381,6 +383,7 @@ class WebKitCaret(browsertab.AbstractCaret):
|
||||
try:
|
||||
url = selected_element.attrib['href']
|
||||
except KeyError:
|
||||
self.follow_selected_done.emit()
|
||||
raise browsertab.WebTabError('Anchor element without '
|
||||
'href!')
|
||||
url = self._tab.url().resolved(QUrl(url))
|
||||
@ -389,6 +392,8 @@ class WebKitCaret(browsertab.AbstractCaret):
|
||||
else:
|
||||
self._tab.openurl(url)
|
||||
|
||||
self.follow_selected_done.emit()
|
||||
|
||||
|
||||
class WebKitZoom(browsertab.AbstractZoom):
|
||||
|
||||
|
@ -336,17 +336,19 @@ class TestFollowSelected:
|
||||
def test_follow_selected_without_a_selection(self, qtbot, caret, selection, web_tab,
|
||||
mode_manager):
|
||||
mode_manager.leave(usertypes.KeyMode.caret)
|
||||
with qtbot.assert_not_emitted(web_tab.load_started):
|
||||
caret.follow_selected()
|
||||
qtbot.wait(self.LOAD_STARTED_DELAY)
|
||||
with qtbot.wait_signal(caret.follow_selected_done):
|
||||
with qtbot.assert_not_emitted(web_tab.load_started):
|
||||
caret.follow_selected()
|
||||
qtbot.wait(self.LOAD_STARTED_DELAY)
|
||||
|
||||
def test_follow_selected_with_text(self, qtbot, caret, selection, web_tab):
|
||||
caret.move_to_next_word()
|
||||
selection.toggle()
|
||||
caret.move_to_end_of_word()
|
||||
with qtbot.assert_not_emitted(web_tab.load_started):
|
||||
caret.follow_selected()
|
||||
qtbot.wait(self.LOAD_STARTED_DELAY)
|
||||
with qtbot.wait_signal(caret.follow_selected_done):
|
||||
with qtbot.assert_not_emitted(web_tab.load_started):
|
||||
caret.follow_selected()
|
||||
qtbot.wait(self.LOAD_STARTED_DELAY)
|
||||
|
||||
@pytest.mark.parametrize('with_js', [True, False])
|
||||
def test_follow_selected_with_link(self, caret, selection, config_stub,
|
||||
|
Loading…
Reference in New Issue
Block a user