Fix scrolling with keys / keyboard event listeners not working on answer side (#2099)

* Revert "Fix reviewer shortcuts being inaccessible due to IME"

This reverts commit 5bf031f1e3.

* Work around WebEngine/IME bug in Qt6
This commit is contained in:
Hikaru Y 2022-10-03 11:53:09 +09:00 committed by GitHub
parent da4d80da2a
commit 76065e843b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

View file

@ -653,12 +653,6 @@ class Reviewer:
def _onTypedAnswer(self, val: None) -> None: def _onTypedAnswer(self, val: None) -> None:
self.typedAnswer = val or "" self.typedAnswer = val or ""
self._showAnswer() self._showAnswer()
self.unfocus_typing_box()
def unfocus_typing_box(self) -> None:
# shifting focus to the bottom area works around a WebEngine/IME bug
# https://github.com/ankitects/anki/issues/1952
self.bottom.web.setFocus()
# Bottom bar # Bottom bar
########################################################################## ##########################################################################

View file

@ -294,8 +294,9 @@ class AnkiWebView(QWebEngineView):
w.close() w.close()
else: else:
# in the main window, removes focus from type in area # in the main window, removes focus from type in area
if mw.state == "review": parent = self.parent()
mw.reviewer.unfocus_typing_box() assert isinstance(parent, QWidget)
parent.setFocus()
break break
w = w.parent() w = w.parent()

View file

@ -237,3 +237,17 @@ export function _blockDefaultDragDropBehavior(): void {
document.ondragover = handler; document.ondragover = handler;
document.ondrop = handler; document.ondrop = handler;
} }
// work around WebEngine/IME bug in Qt6
// https://github.com/ankitects/anki/issues/1952
const dummyButton = document.createElement("button");
dummyButton.style.position = "absolute";
dummyButton.style.left = "-9999px";
document.addEventListener("focusout", (event) => {
const target = event.target;
if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {
document.body.appendChild(dummyButton);
dummyButton.focus();
document.body.removeChild(dummyButton);
}
});