mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Close MathJax editor when Esc is pressed (#2237)
This commit is contained in:
parent
8165f95cde
commit
6ef460e74a
4 changed files with 11 additions and 9 deletions
|
@ -1,9 +1,11 @@
|
||||||
/* Copyright: Ankitects Pty Ltd and contributors
|
/* Copyright: Ankitects Pty Ltd and contributors
|
||||||
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
|
* 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) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
let isText = 0;
|
let isText = 0;
|
||||||
|
|
|
@ -247,12 +247,6 @@ class AnkiWebView(QWebEngineView):
|
||||||
|
|
||||||
self.resetHandlers()
|
self.resetHandlers()
|
||||||
self._filterSet = False
|
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)
|
gui_hooks.theme_did_change.append(self.on_theme_did_change)
|
||||||
|
|
||||||
def set_title(self, title: str) -> None:
|
def set_title(self, title: str) -> None:
|
||||||
|
@ -601,6 +595,8 @@ html {{ {font} }}
|
||||||
if cmd == "domDone":
|
if cmd == "domDone":
|
||||||
self._domDone = True
|
self._domDone = True
|
||||||
self._maybeRunActions()
|
self._maybeRunActions()
|
||||||
|
elif cmd == "close":
|
||||||
|
self.onEsc()
|
||||||
else:
|
else:
|
||||||
handled, result = gui_hooks.webview_did_receive_js_message(
|
handled, result = gui_hooks.webview_did_receive_js_message(
|
||||||
(False, None), cmd, self._bridge_context
|
(False, None), cmd, self._bridge_context
|
||||||
|
|
|
@ -51,7 +51,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
editor.on(
|
editor.on(
|
||||||
"keydown",
|
"keydown",
|
||||||
(_instance: CodeMirrorLib.Editor, event: KeyboardEvent): void => {
|
(_instance: CodeMirrorLib.Editor, event: KeyboardEvent): void => {
|
||||||
if (isArrowLeft(event)) {
|
if (event.key === "Escape") {
|
||||||
|
dispatch("close");
|
||||||
|
event.stopPropagation();
|
||||||
|
} else if (isArrowLeft(event)) {
|
||||||
direction = "start";
|
direction = "start";
|
||||||
} else if (isArrowRight(event)) {
|
} else if (isArrowRight(event)) {
|
||||||
direction = "end";
|
direction = "end";
|
||||||
|
|
|
@ -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?)
|
// the user has to click twice (focus is called before blur?)
|
||||||
resetHandle();
|
resetHandle();
|
||||||
}}
|
}}
|
||||||
|
on:close={resetHandle}
|
||||||
let:editor={mathjaxEditor}
|
let:editor={mathjaxEditor}
|
||||||
>
|
>
|
||||||
<Shortcut
|
<Shortcut
|
||||||
|
|
Loading…
Reference in a new issue