mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
Fix missizing of HandleSelection when first moving from empty to Mathjax
This commit is contained in:
parent
88fd31a099
commit
06d1ec6af4
2 changed files with 24 additions and 13 deletions
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { onMount, getContext } from "svelte";
|
||||
import { onMount, onDestroy, getContext } from "svelte";
|
||||
import { nightModeKey } from "components/context-keys";
|
||||
import { convertMathjax } from "./mathjax";
|
||||
|
||||
|
@ -22,18 +22,26 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
let encoded: string;
|
||||
let imageHeight: number;
|
||||
|
||||
$: {
|
||||
encoded = encodeURIComponent(converted);
|
||||
setTimeout(() => (imageHeight = image.getBoundingClientRect().height));
|
||||
}
|
||||
$: encoded = encodeURIComponent(converted);
|
||||
|
||||
let image: HTMLImageElement;
|
||||
|
||||
const observer = new ResizeObserver(() => {
|
||||
imageHeight = image.getBoundingClientRect().height;
|
||||
setTimeout(() => image.dispatchEvent(new Event("resize")));
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
observer.observe(image);
|
||||
if (autofocus) {
|
||||
image.click();
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
observer.unobserve(image);
|
||||
observer.disconnect();
|
||||
});
|
||||
</script>
|
||||
|
||||
<img
|
||||
|
|
|
@ -36,19 +36,22 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
return image.closest("anki-mathjax")! as HTMLElement;
|
||||
}
|
||||
|
||||
function onEditorUpdate(event: CustomEvent) {
|
||||
getComponent(activeImage!).dataset.mathjax = event.detail.mathjax;
|
||||
const onImageResize = (resolve: () => void) => (): void => {
|
||||
errorMessage = activeImage!.title;
|
||||
updateSelection().then(resolve);
|
||||
};
|
||||
|
||||
function onEditorUpdate(event: CustomEvent): Promise<void> {
|
||||
let selectionResolve: (value: void) => void;
|
||||
const afterSelectionUpdate = new Promise((resolve) => {
|
||||
const afterSelectionUpdate = new Promise((resolve: (value: void) => void) => {
|
||||
selectionResolve = resolve;
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
errorMessage = activeImage!.title;
|
||||
await updateSelection();
|
||||
selectionResolve();
|
||||
});
|
||||
const imageResize = onImageResize(selectionResolve!);
|
||||
|
||||
activeImage!.addEventListener("resize", imageResize, { once: true });
|
||||
/* this updates the image in Mathjax.svelte */
|
||||
getComponent(activeImage!).dataset.mathjax = event.detail.mathjax;
|
||||
|
||||
return afterSelectionUpdate;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue