Close MathJax editor when Esc is pressed (#2237)

This commit is contained in:
Abdo 2022-12-05 08:08:38 +03:00 committed by GitHub
parent 8165f95cde
commit 6ef460e74a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 9 deletions

View file

@ -1,9 +1,11 @@
/* Copyright: Ankitects Pty Ltd and contributors
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
// prevent backspace key from going back a page
document.addEventListener("keydown", function(evt: KeyboardEvent) {
if (evt.keyCode !== 8) {
if (evt.keyCode === 27) {
pycmd("close");
} // prevent backspace key from going back a page
else if (evt.keyCode !== 8) {
return;
}
let isText = 0;

View file

@ -247,12 +247,6 @@ class AnkiWebView(QWebEngineView):
self.resetHandlers()
self._filterSet = False
QShortcut( # type: ignore
QKeySequence("Esc"),
self,
context=Qt.ShortcutContext.WidgetWithChildrenShortcut,
activated=self.onEsc,
)
gui_hooks.theme_did_change.append(self.on_theme_did_change)
def set_title(self, title: str) -> None:
@ -601,6 +595,8 @@ html {{ {font} }}
if cmd == "domDone":
self._domDone = True
self._maybeRunActions()
elif cmd == "close":
self.onEsc()
else:
handled, result = gui_hooks.webview_did_receive_js_message(
(False, None), cmd, self._bridge_context

View file

@ -51,7 +51,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
editor.on(
"keydown",
(_instance: CodeMirrorLib.Editor, event: KeyboardEvent): void => {
if (isArrowLeft(event)) {
if (event.key === "Escape") {
dispatch("close");
event.stopPropagation();
} else if (isArrowLeft(event)) {
direction = "start";
} else if (isArrowRight(event)) {
direction = "end";

View file

@ -228,6 +228,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
// the user has to click twice (focus is called before blur?)
resetHandle();
}}
on:close={resetHandle}
let:editor={mathjaxEditor}
>
<Shortcut