Move setMathjaxEnabled()

This commit is contained in:
Abdo 2025-05-28 11:28:36 +03:00
parent 15cbbeea24
commit 544b5f54d7
5 changed files with 40 additions and 14 deletions

View file

@ -1260,14 +1260,6 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
def insertMathjaxChemistry(self) -> None:
self.web.eval("wrap('\\\\(\\\\ce{', '}\\\\)');")
def toggleMathjax(self) -> None:
self.mw.col.set_config(
"renderMathjax", not self.mw.col.get_config("renderMathjax", False)
)
# hackily redraw the page
self.setupWeb()
self.loadNoteKeepingFocus()
def toggleShrinkImages(self) -> None:
self.mw.col.set_config(
"shrinkEditorImages",
@ -1309,7 +1301,6 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
mathjaxInline=Editor.insertMathjaxInline,
mathjaxBlock=Editor.insertMathjaxBlock,
mathjaxChemistry=Editor.insertMathjaxChemistry,
toggleMathjax=Editor.toggleMathjax,
toggleShrinkImages=Editor.toggleShrinkImages,
toggleCloseHTMLTags=Editor.toggleCloseHTMLTags,
addImageForOcclusion=Editor.select_image_and_occlude,

View file

@ -33,6 +33,7 @@ import aqt.operations
from anki import frontend_pb2, generic_pb2, hooks
from anki.collection import OpChanges, OpChangesOnly, Progress, SearchNode
from anki.decks import UpdateDeckConfigs
from anki.errors import NotFoundError
from anki.scheduler.v3 import SchedulingStatesWithContext, SetSchedulingStatesRequest
from anki.utils import dev_mode
from aqt.changenotetype import ChangeNotetypeDialog
@ -654,6 +655,17 @@ def set_meta_json() -> bytes:
return set_setting_json(aqt.mw.pm.meta.__setitem__)
def get_config_json() -> bytes:
try:
return get_setting_json(aqt.mw.col.conf.get_immutable)
except NotFoundError:
return generic_pb2.Json(json=b"null").SerializeToString()
def set_config_json() -> bytes:
return set_setting_json(aqt.mw.col.set_config)
post_handler_list = [
congrats_info,
get_deck_configs_for_update,
@ -674,6 +686,7 @@ post_handler_list = [
set_profile_config_json,
get_meta_json,
set_meta_json,
get_config_json,
]
@ -723,6 +736,8 @@ exposed_backend_list = [
# CardRenderingService
"encode_iri_paths",
"decode_iri_paths",
# ConfigService
"set_config_json",
]

View file

@ -1,7 +1,14 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { getMetaJson, getProfileConfigJson, setMetaJson, setProfileConfigJson } from "@generated/backend";
import {
getConfigJson,
getMetaJson,
getProfileConfigJson,
setConfigJson,
setMetaJson,
setProfileConfigJson,
} from "@generated/backend";
async function getSettingJson(key: string, backendGetter: (key: string) => Promise<any>): Promise<any> {
const decoder = new TextDecoder();
@ -34,3 +41,15 @@ export async function getMeta(key: string): Promise<any> {
export async function setMeta(key: string, value: any): Promise<void> {
return await setSettingJson(key, value, async (k, v) => await setMetaJson({ key: k, valueJson: v }));
}
export async function getColConfig(key: string): Promise<any> {
return await getSettingJson(key, async (k) => await getConfigJson({ val: k }));
}
export async function setColConfig(key: string, value: any): Promise<void> {
return await setSettingJson(
key,
value,
async (k, v) => await setConfigJson({ key: k, valueJson: v, undoable: true }),
);
}

View file

@ -448,7 +448,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
decodeIriPaths,
} from "@generated/backend";
import { wrapInternal } from "@tslib/wrap";
import { getProfileConfig, getMeta, setMeta } from "@tslib/profile";
import { getProfileConfig, getMeta, setMeta, getColConfig } from "@tslib/profile";
import Shortcut from "$lib/components/Shortcut.svelte";
import { mathjaxConfig } from "$lib/editable/mathjax-element.svelte";
@ -643,8 +643,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
toolbar.inlineButtons?.setColorButtons([lastTextColor, lastHighlightColor]);
setTags(tags);
setTagsCollapsed(await getMeta(tagsCollapsedMetaKey));
// TODO: renderMathjax col config
setMathjaxEnabled(true);
setMathjaxEnabled((await getColConfig("renderMathjax")) ?? true);
// TODO: shrinkEditorImages col config
setShrinkImages(true);
// TODO: closeHTMLTags col config

View file

@ -17,6 +17,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { mathjaxConfig } from "$lib/editable/mathjax-element.svelte";
import { shrinkImagesByDefault } from "../image-overlay/ImageOverlay.svelte";
import { closeHTMLTags } from "../plain-text-input/PlainTextInput.svelte";
import { setColConfig } from "@tslib/profile";
let showFloating = false;
@ -28,7 +29,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
function toggleShowMathjax(_evt: MouseEvent): void {
mathjaxConfig.enabled = !mathjaxConfig.enabled;
bridgeCommand("toggleMathjax");
setColConfig("renderMathjax", mathjaxConfig.enabled);
// FIXME: refresh
}
function toggleCloseHTMLTags(_evt: MouseEvent): void {