From 91178d3d5870308158ffe13f3db47a5f9d50419b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 10 Apr 2019 16:12:43 +1000 Subject: [PATCH] extend altgr fix to editor fields, and add warning about helper extends https://github.com/dae/anki/pull/298 --- aqt/webview.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/aqt/webview.py b/aqt/webview.py index 6ff5cfe75..b4905e3b8 100644 --- a/aqt/webview.py +++ b/aqt/webview.py @@ -84,7 +84,9 @@ class AnkiWebPage(QWebEnginePage): def _onCmd(self, str): return self._onBridgeCmd(str) -def runJavaScriptSync(page, js, timeout=500): +# this is a hack to work around a qt bug - do not use this function in add-ons +# as it will likely go away in the future +def _runJavaScriptSync(page, js, timeout=500): result = None eventLoop = QEventLoop() called = False @@ -148,8 +150,11 @@ class AnkiWebView(QWebEngineView): # alt-gr bug workaround exceptChars = (str(num) for num in range(1, 10)) if evt.text() not in exceptChars: - js = '["INPUT", "TEXTAREA"].indexOf(document.activeElement.tagName) !== -1' - if runJavaScriptSync(self.page(), js, timeout=100): + js = ''' +var e=document.activeElement; +(e.tagName === "DIV" && e.contentEditable) || +["INPUT", "TEXTAREA"].indexOf(document.activeElement.tagName) !== -1''' + if _runJavaScriptSync(self.page(), js, timeout=100): evt.accept() return True return QWebEngineView.event(self, evt)