mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Debounce mathjax rendering to avoid stalling (#3827)
* move change-timer to editable * debounce mathjax rendering
This commit is contained in:
parent
e373b0ed9b
commit
8ec139f62a
3 changed files with 10 additions and 4 deletions
|
@ -38,25 +38,31 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import { pageTheme } from "$lib/sveltelib/theme";
|
||||
|
||||
import { convertMathjax, unescapeSomeEntities } from "./mathjax";
|
||||
import { ChangeTimer } from "./change-timer";
|
||||
|
||||
export let mathjax: string;
|
||||
export let block: boolean;
|
||||
export let fontSize: number;
|
||||
|
||||
let converted: string, title: string;
|
||||
|
||||
const debouncedMathjax = writable(mathjax);
|
||||
const debouncer = new ChangeTimer();
|
||||
$: debouncer.schedule(() => debouncedMathjax.set(mathjax), 500);
|
||||
|
||||
$: {
|
||||
const cache = getCache($pageTheme.isDark, fontSize);
|
||||
const entry = cache.get(mathjax);
|
||||
const entry = cache.get($debouncedMathjax);
|
||||
if (entry) {
|
||||
[converted, title] = entry;
|
||||
} else {
|
||||
const entry = convertMathjax(
|
||||
unescapeSomeEntities(mathjax),
|
||||
unescapeSomeEntities($debouncedMathjax),
|
||||
$pageTheme.isDark,
|
||||
fontSize,
|
||||
);
|
||||
[converted, title] = entry;
|
||||
cache.set(mathjax, entry);
|
||||
cache.set($debouncedMathjax, entry);
|
||||
}
|
||||
}
|
||||
$: empty = title === "MathJax";
|
||||
|
|
|
@ -57,7 +57,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
type ImageLoadedEvent,
|
||||
resetIOImage,
|
||||
} from "../routes/image-occlusion/mask-editor";
|
||||
import { ChangeTimer } from "./change-timer";
|
||||
import { ChangeTimer } from "../editable/change-timer";
|
||||
import { clearableArray } from "./destroyable";
|
||||
import DuplicateLink from "./DuplicateLink.svelte";
|
||||
import EditorToolbar from "./editor-toolbar";
|
||||
|
|
Loading…
Reference in a new issue