From 14f4107dfda3c75d8e0eeb1c44141ceb962cd3c6 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 23 Oct 2018 16:47:01 +1000 Subject: [PATCH] deal with onclick handlers that don't return false Because is set to the media server URL, causes a page transition from the current setHtml() page data. Previous Qt versions allowed us to just ignore the request, but now returning False in acceptNavigationRequest() causes the subsequent page navigation to be rejected as well, resulting in no visible change when clicking on a deck in the deck list. To deal with this, Anki will now warn when such navigation requests come in, as the anchors need to be updated to return false. pycmd() has been updated to return false to make returning in onclick easier. Also use QUrl.matches() instead of converting the potentially long URL to a string. --- aqt/deckbrowser.py | 2 +- aqt/webview.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/aqt/deckbrowser.py b/aqt/deckbrowser.py index 6d61ef1d1..5a1463d12 100644 --- a/aqt/deckbrowser.py +++ b/aqt/deckbrowser.py @@ -176,7 +176,7 @@ where id > ?""", (self.mw.col.sched.dayCutoff-86400)*1000) buf += """ %s%s%s"""% ( + href=# onclick="return pycmd('open:%d')">%s"""% ( indent(), collapse, extraclass, did, name) # due counts def nonzeroColour(cnt, colour): diff --git a/aqt/webview.py b/aqt/webview.py index cc0fce5a0..ca4e18191 100644 --- a/aqt/webview.py +++ b/aqt/webview.py @@ -49,7 +49,8 @@ class AnkiWebPage(QWebEnginePage): } } - channel.objects.py.cmd(arg, resultCB); + channel.objects.py.cmd(arg, resultCB); + return false; } pycmd("domDone"); }); @@ -71,9 +72,10 @@ class AnkiWebPage(QWebEnginePage): # data: links generated by setHtml() if url.scheme() == "data": return True + # catch buggy links from aqt import mw - # ignore href=# - if url.toString().startswith(mw.serverURL()): + if url.matches(QUrl(mw.serverURL()), QUrl.RemoveFragment): + sys.stderr.write("onclick handler needs to return false\n") return False # load all other links in browser openLink(url)