diff --git a/ftl/core-repo b/ftl/core-repo index 056ff8105..c74c15b7f 160000 --- a/ftl/core-repo +++ b/ftl/core-repo @@ -1 +1 @@ -Subproject commit 056ff810563e7a7220aa723611abdf832ed7f437 +Subproject commit c74c15b7f82c0f184910e5b6f695b635e6d81faf diff --git a/ftl/qt-repo b/ftl/qt-repo index 45155310c..06ad12df7 160000 --- a/ftl/qt-repo +++ b/ftl/qt-repo @@ -1 +1 @@ -Subproject commit 45155310c3302cbbbe645dec52ca196894422463 +Subproject commit 06ad12df7a2c8400cf64e9c7b986e9ee722e5b38 diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index e17cf8823..b6c28c308 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -1246,7 +1246,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too highest += 1 # must start at 1 highest = max(1, highest) - self.web.eval("wrapCloze(%d);" % highest) + self.web.eval("wrap('{{c%d::', '}}');" % highest) def setupForegroundButton(self) -> None: self.fcolour = self.mw.pm.profile.get("lastColour", "#00f") diff --git a/ts/editor/ClozeButtons.svelte b/ts/editor/ClozeButtons.svelte index 11b8ca933..03d346012 100644 --- a/ts/editor/ClozeButtons.svelte +++ b/ts/editor/ClozeButtons.svelte @@ -56,16 +56,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html async function onIncrementCloze(): Promise { const highestCloze = getCurrentHighestCloze(true); - dispatch("cloze", { - n: highestCloze, + dispatch("surround", { + prefix: `{{c${highestCloze}::`, + suffix: "}}", }); } async function onSameCloze(): Promise { const highestCloze = getCurrentHighestCloze(false); - dispatch("cloze", { - n: highestCloze, + dispatch("surround", { + prefix: `{{c${highestCloze}::`, + suffix: "}}", }); } diff --git a/ts/editor/NoteEditor.svelte b/ts/editor/NoteEditor.svelte index 5b24fdad4..96b1344eb 100644 --- a/ts/editor/NoteEditor.svelte +++ b/ts/editor/NoteEditor.svelte @@ -393,7 +393,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { ImageOcclusionFieldIndexes } from "@generated/anki/image_occlusion_pb"; import { getImageOcclusionFields } from "@generated/backend"; - import { wrapClozeInternal, wrapInternal } from "@tslib/wrap"; + import { wrapInternal } from "@tslib/wrap"; import Shortcut from "$lib/components/Shortcut.svelte"; @@ -548,16 +548,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html }); } - function wrapCloze(n: number): void { - if (!$focusedInput || !editingInputIsRichText($focusedInput)) { - return; - } - - $focusedInput.element.then((element) => { - wrapClozeInternal(element, n); - }); - } - Object.assign(globalThis, { saveSession, setFields, @@ -576,7 +566,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html setNoteId, setNotetypeMeta, wrap, - wrapCloze, setMathjaxEnabled, setShrinkImages, setCloseHTMLTags, diff --git a/ts/editor/editor-toolbar/RichTextClozeButtons.svelte b/ts/editor/editor-toolbar/RichTextClozeButtons.svelte index b41b37e85..04aed2581 100644 --- a/ts/editor/editor-toolbar/RichTextClozeButtons.svelte +++ b/ts/editor/editor-toolbar/RichTextClozeButtons.svelte @@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html --> - + diff --git a/ts/editor/mathjax-overlay/MathjaxButtons.svelte b/ts/editor/mathjax-overlay/MathjaxButtons.svelte index 01bfe658b..03098c96a 100644 --- a/ts/editor/mathjax-overlay/MathjaxButtons.svelte +++ b/ts/editor/mathjax-overlay/MathjaxButtons.svelte @@ -40,7 +40,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - + { + on:surround={async ({ detail }) => { const editor = await mathjaxEditor.editor; - const { n } = detail; + const { prefix, suffix } = detail; + editor.replaceSelection( - `{{c${n}::` + editor.getSelection() + "}}", + prefix + editor.getSelection() + suffix, ); }} /> diff --git a/ts/lib/tslib/wrap.ts b/ts/lib/tslib/wrap.ts index 63deb9acf..39b10e9d1 100644 --- a/ts/lib/tslib/wrap.ts +++ b/ts/lib/tslib/wrap.ts @@ -1,7 +1,6 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import { placeCaretAfter } from "../domlib/place-caret"; import { getRange, getSelection } from "./cross-browser"; function wrappedExceptForWhitespace(text: string, front: string, back: string): string { @@ -54,36 +53,3 @@ export function wrapInternal( moveCursorInside(selection, back); } } - -export function wrapClozeInternal(base: Element, n: number): void { - const selection = getSelection(base)!; - const range = getRange(selection); - if (!range) { - return; - } - - const fragment = range.extractContents(); - if (fragment.childNodes.length === 0) { - document.execCommand("inserthtml", false, `{{c${n}::}}`); - moveCursorInside(selection, "}}"); - } else { - const startNode = document.createTextNode(`{{c${n}::`); - const endNode = document.createTextNode("}}"); - range.insertNode(endNode); - range.insertNode(fragment); - range.insertNode(startNode); - placeCaretAfter(endNode); - // Remove empty
  • elements added by extractContents() - const elementsToCheck = [ - startNode.previousElementSibling, - startNode.nextElementSibling, - endNode.previousElementSibling, - endNode.nextElementSibling, - ]; - for (const element of elementsToCheck) { - if (element?.tagName === "LI" && !element?.textContent?.trim()) { - element.remove(); - } - } - } -}