Fix two issues with MathJax editor (#2550)

* Fix MathJax editor not closing when changing notes via shortcut

Another commit will remove the on:blur handler set for <MathjaxEditor>,
in which case the function will also be called when changing notes with
a mouse click.

* Don't close MathJax editor on blur event

Closing MathJax editor on a blur event caused it to close even when
it should not.
e.g.
- when switching to another application
- when right-clicking to bring up the context menu
- when clicking on the empty space around CodeMirror
This commit is contained in:
Hikaru Y 2023-06-19 12:55:40 +09:00 committed by GitHub
parent e4cc77bbf6
commit 1aabff9248
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View file

@ -60,6 +60,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import ImageOverlay from "./image-overlay";
import { shrinkImagesByDefault } from "./image-overlay/ImageOverlay.svelte";
import MathjaxOverlay from "./mathjax-overlay";
import { closeMathjaxEditor } from "./mathjax-overlay/MathjaxEditor.svelte";
import Notification from "./Notification.svelte";
import PlainTextInput from "./plain-text-input";
import { closeHTMLTags } from "./plain-text-input/PlainTextInput.svelte";
@ -292,6 +293,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
function saveNow(): void {
closeMathjaxEditor?.();
$commitTagEdits();
saveFieldNow();
}

View file

@ -2,6 +2,17 @@
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script context="module" lang="ts">
import { writable } from "svelte/store";
export let closeMathjaxEditor: (() => void) | null = null;
const closeSignalStore = writable<symbol>(Symbol(), (set) => {
closeMathjaxEditor = () => set(Symbol());
return () => (closeMathjaxEditor = null);
});
</script>
<script lang="ts">
import * as tr from "@tslib/ftl";
import { noop } from "@tslib/functional";
@ -94,6 +105,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
});
});
$: $closeSignalStore, dispatch("close");
</script>
<div class="mathjax-editor" class:light-theme={!$pageTheme.isDark}>

View file

@ -229,10 +229,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
placeHandle(true);
resetHandle();
}}
on:blur={async () => {
await tick();
await resetHandle();
}}
on:close={resetHandle}
let:editor={mathjaxEditor}
>