extend altgr fix to editor fields, and add warning about helper

extends https://github.com/dae/anki/pull/298
This commit is contained in:
Damien Elmes 2019-04-10 16:12:43 +10:00
parent 4a167304a6
commit 91178d3d58

View file

@ -84,7 +84,9 @@ class AnkiWebPage(QWebEnginePage):
def _onCmd(self, str): def _onCmd(self, str):
return self._onBridgeCmd(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 result = None
eventLoop = QEventLoop() eventLoop = QEventLoop()
called = False called = False
@ -148,8 +150,11 @@ class AnkiWebView(QWebEngineView):
# alt-gr bug workaround # alt-gr bug workaround
exceptChars = (str(num) for num in range(1, 10)) exceptChars = (str(num) for num in range(1, 10))
if evt.text() not in exceptChars: if evt.text() not in exceptChars:
js = '["INPUT", "TEXTAREA"].indexOf(document.activeElement.tagName) !== -1' js = '''
if runJavaScriptSync(self.page(), js, timeout=100): 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() evt.accept()
return True return True
return QWebEngineView.event(self, evt) return QWebEngineView.event(self, evt)