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: def insertMathjaxChemistry(self) -> None:
self.web.eval("wrap('\\\\(\\\\ce{', '}\\\\)');") 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: def toggleShrinkImages(self) -> None:
self.mw.col.set_config( self.mw.col.set_config(
"shrinkEditorImages", "shrinkEditorImages",
@ -1309,7 +1301,6 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
mathjaxInline=Editor.insertMathjaxInline, mathjaxInline=Editor.insertMathjaxInline,
mathjaxBlock=Editor.insertMathjaxBlock, mathjaxBlock=Editor.insertMathjaxBlock,
mathjaxChemistry=Editor.insertMathjaxChemistry, mathjaxChemistry=Editor.insertMathjaxChemistry,
toggleMathjax=Editor.toggleMathjax,
toggleShrinkImages=Editor.toggleShrinkImages, toggleShrinkImages=Editor.toggleShrinkImages,
toggleCloseHTMLTags=Editor.toggleCloseHTMLTags, toggleCloseHTMLTags=Editor.toggleCloseHTMLTags,
addImageForOcclusion=Editor.select_image_and_occlude, 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 import frontend_pb2, generic_pb2, hooks
from anki.collection import OpChanges, OpChangesOnly, Progress, SearchNode from anki.collection import OpChanges, OpChangesOnly, Progress, SearchNode
from anki.decks import UpdateDeckConfigs from anki.decks import UpdateDeckConfigs
from anki.errors import NotFoundError
from anki.scheduler.v3 import SchedulingStatesWithContext, SetSchedulingStatesRequest from anki.scheduler.v3 import SchedulingStatesWithContext, SetSchedulingStatesRequest
from anki.utils import dev_mode from anki.utils import dev_mode
from aqt.changenotetype import ChangeNotetypeDialog from aqt.changenotetype import ChangeNotetypeDialog
@ -654,6 +655,17 @@ def set_meta_json() -> bytes:
return set_setting_json(aqt.mw.pm.meta.__setitem__) 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 = [ post_handler_list = [
congrats_info, congrats_info,
get_deck_configs_for_update, get_deck_configs_for_update,
@ -674,6 +686,7 @@ post_handler_list = [
set_profile_config_json, set_profile_config_json,
get_meta_json, get_meta_json,
set_meta_json, set_meta_json,
get_config_json,
] ]
@ -723,6 +736,8 @@ exposed_backend_list = [
# CardRenderingService # CardRenderingService
"encode_iri_paths", "encode_iri_paths",
"decode_iri_paths", "decode_iri_paths",
# ConfigService
"set_config_json",
] ]

View file

@ -1,7 +1,14 @@
// 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
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> { async function getSettingJson(key: string, backendGetter: (key: string) => Promise<any>): Promise<any> {
const decoder = new TextDecoder(); 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> { export async function setMeta(key: string, value: any): Promise<void> {
return await setSettingJson(key, value, async (k, v) => await setMetaJson({ key: k, valueJson: v })); 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, decodeIriPaths,
} from "@generated/backend"; } from "@generated/backend";
import { wrapInternal } from "@tslib/wrap"; 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 Shortcut from "$lib/components/Shortcut.svelte";
import { mathjaxConfig } from "$lib/editable/mathjax-element.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]); toolbar.inlineButtons?.setColorButtons([lastTextColor, lastHighlightColor]);
setTags(tags); setTags(tags);
setTagsCollapsed(await getMeta(tagsCollapsedMetaKey)); setTagsCollapsed(await getMeta(tagsCollapsedMetaKey));
// TODO: renderMathjax col config setMathjaxEnabled((await getColConfig("renderMathjax")) ?? true);
setMathjaxEnabled(true);
// TODO: shrinkEditorImages col config // TODO: shrinkEditorImages col config
setShrinkImages(true); setShrinkImages(true);
// TODO: closeHTMLTags col config // 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 { mathjaxConfig } from "$lib/editable/mathjax-element.svelte";
import { shrinkImagesByDefault } from "../image-overlay/ImageOverlay.svelte"; import { shrinkImagesByDefault } from "../image-overlay/ImageOverlay.svelte";
import { closeHTMLTags } from "../plain-text-input/PlainTextInput.svelte"; import { closeHTMLTags } from "../plain-text-input/PlainTextInput.svelte";
import { setColConfig } from "@tslib/profile";
let showFloating = false; 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 { function toggleShowMathjax(_evt: MouseEvent): void {
mathjaxConfig.enabled = !mathjaxConfig.enabled; mathjaxConfig.enabled = !mathjaxConfig.enabled;
bridgeCommand("toggleMathjax"); setColConfig("renderMathjax", mathjaxConfig.enabled);
// FIXME: refresh
} }
function toggleCloseHTMLTags(_evt: MouseEvent): void { function toggleCloseHTMLTags(_evt: MouseEvent): void {