Revert "Workaround for AltGr '@' issue."

This reverts commit 1e433a7cdd and
91178d3d58

Due to regressions this will be moved into an optional add-on, at
least for now.
This commit is contained in:
Damien Elmes 2019-04-16 13:37:27 +10:00
parent 015bb71cca
commit f80d250b47

View file

@ -84,32 +84,6 @@ class AnkiWebPage(QWebEnginePage):
def _onCmd(self, str): def _onCmd(self, str):
return self._onBridgeCmd(str) return self._onBridgeCmd(str)
# 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
def callback(val):
nonlocal result, called
result = val
called = True
eventLoop.quit()
page.runJavaScript(js, callback)
if not called:
timer = QTimer()
timer.setSingleShot(True)
timer.timeout.connect(eventLoop.quit)
timer.start(timeout)
eventLoop.exec_()
if not called:
print('runJavaScriptSync() timed out')
return result
# Main web view # Main web view
########################################################################## ##########################################################################
@ -145,20 +119,6 @@ class AnkiWebView(QWebEngineView):
QShortcut(QKeySequence("ctrl+shift+v"), self, QShortcut(QKeySequence("ctrl+shift+v"), self,
context=Qt.WidgetWithChildrenShortcut, activated=self.onPaste) context=Qt.WidgetWithChildrenShortcut, activated=self.onPaste)
def event(self, evt):
if evt.type() == QEvent.ShortcutOverride:
# alt-gr bug workaround
exceptChars = (str(num) for num in range(1, 10))
if evt.text() not in exceptChars:
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)
def eventFilter(self, obj, evt): def eventFilter(self, obj, evt):
# disable pinch to zoom gesture # disable pinch to zoom gesture
if isinstance(evt, QNativeGestureEvent): if isinstance(evt, QNativeGestureEvent):