From d7deb5fafccb764c6492eca48472d237382e1e3a Mon Sep 17 00:00:00 2001
From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com>
Date: Wed, 12 Oct 2022 06:34:25 +0200
Subject: [PATCH] Move MathJax toggle to OptionsButton and fix two bugs (#2126)
* Rename MathJax toggle and move it to OptionsButton
* Apply MathJax setting to newly added blocks
* Actually remove MathJax element on delete
---
ftl/core/editing.ftl | 2 +-
ts/editor/editor-toolbar/LatexButton.svelte | 28 ++++++++++---------
ts/editor/editor-toolbar/OptionsButton.svelte | 10 +++++++
.../mathjax-overlay/MathjaxOverlay.svelte | 14 ++++++----
4 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/ftl/core/editing.ftl b/ftl/core/editing.ftl
index 75b915f11..b91dcb390 100644
--- a/ftl/core/editing.ftl
+++ b/ftl/core/editing.ftl
@@ -60,7 +60,7 @@ editing-collapse-field = Collapse field
editing-underline-text = Underline text
editing-unordered-list = Unordered list
editing-warning-cloze-deletions-will-not-work = Warning, cloze deletions will not work until you switch the type at the top to Cloze.
-editing-toggle-mathjax-rendering = Toggle MathJax Rendering
+editing-mathjax-preview = MathJax Preview
editing-shrink-images = Shrink Images
editing-close-html-tags = Auto-close HTML tags
diff --git a/ts/editor/editor-toolbar/LatexButton.svelte b/ts/editor/editor-toolbar/LatexButton.svelte
index ba5a6b81d..adfbb5610 100644
--- a/ts/editor/editor-toolbar/LatexButton.svelte
+++ b/ts/editor/editor-toolbar/LatexButton.svelte
@@ -9,7 +9,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import Shortcut from "../../components/Shortcut.svelte";
import WithFloating from "../../components/WithFloating.svelte";
import { mathjaxConfig } from "../../editable/mathjax-element";
- import { bridgeCommand } from "../../lib/bridgecommand";
import * as tr from "../../lib/ftl";
import { getPlatformString } from "../../lib/shortcuts";
import { wrapInternal } from "../../lib/wrap";
@@ -27,15 +26,27 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
function onMathjaxInline(): void {
- surround("", "");
+ if (mathjaxConfig.enabled) {
+ surround("", "");
+ } else {
+ surround("\\(", "\\)");
+ }
}
function onMathjaxBlock(): void {
- surround('', "");
+ if (mathjaxConfig.enabled) {
+ surround('', "");
+ } else {
+ surround("\\[", "\\]");
+ }
}
function onMathjaxChemistry(): void {
- surround('\\ce{', "}");
+ if (mathjaxConfig.enabled) {
+ surround('\\ce{', "}");
+ } else {
+ surround("\\(\\ce{", "}\\)");
+ }
}
function onLatex(): void {
@@ -50,11 +61,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
surround("[$$]", "[/$$]");
}
- function toggleShowMathjax(): void {
- mathjaxConfig.enabled = !mathjaxConfig.enabled;
- bridgeCommand("toggleMathjax");
- }
-
type LatexItem = [() => void, string, string];
const dropdownItems: LatexItem[] = [
@@ -94,10 +100,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
>
{/each}
-
-
- {tr.editingToggleMathjaxRendering()}
-
diff --git a/ts/editor/editor-toolbar/OptionsButton.svelte b/ts/editor/editor-toolbar/OptionsButton.svelte
index a871b3a95..4386aae92 100644
--- a/ts/editor/editor-toolbar/OptionsButton.svelte
+++ b/ts/editor/editor-toolbar/OptionsButton.svelte
@@ -8,6 +8,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import IconButton from "../../components/IconButton.svelte";
import Popover from "../../components/Popover.svelte";
import WithFloating from "../../components/WithFloating.svelte";
+ import { mathjaxConfig } from "../../editable/mathjax-element";
import { bridgeCommand } from "../../lib/bridgecommand";
import * as tr from "../../lib/ftl";
import { shrinkImagesByDefault } from "../image-overlay/ImageOverlay.svelte";
@@ -22,6 +23,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
showFloating = false;
}
+ function toggleShowMathjax(_evt: MouseEvent): void {
+ mathjaxConfig.enabled = !mathjaxConfig.enabled;
+ bridgeCommand("toggleMathjax");
+ }
+
function toggleCloseHTMLTags(_evt: MouseEvent): void {
$closeHTMLTags = !$closeHTMLTags;
bridgeCommand("toggleCloseHTMLTags");
@@ -50,6 +56,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
{tr.editingShrinkImages()}
+
+
+ {tr.editingMathjaxPreview()}
+
{tr.editingCloseHtmlTags()}
diff --git a/ts/editor/mathjax-overlay/MathjaxOverlay.svelte b/ts/editor/mathjax-overlay/MathjaxOverlay.svelte
index 967fc8883..677bc9095 100644
--- a/ts/editor/mathjax-overlay/MathjaxOverlay.svelte
+++ b/ts/editor/mathjax-overlay/MathjaxOverlay.svelte
@@ -65,14 +65,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
}
+ function clear(): void {
+ unsubscribe();
+ activeImage = null;
+ mathjaxElement = null;
+ }
+
async function resetHandle(): Promise {
selectAll = false;
position = undefined;
if (activeImage && mathjaxElement) {
- unsubscribe();
- activeImage = null;
- mathjaxElement = null;
+ clear();
}
allow();
@@ -220,8 +224,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}}
on:delete={async () => {
placeCaretAfter(activeImage);
- activeImage.remove();
- await resetHandle();
+ mathjaxElement?.remove();
+ clear();
}}
on:surround={async ({ detail }) => {
const editor = await mathjaxEditor.editor;