mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00

* Put PlainTextInput into its own directory * Create a directory for RichTextInput * Create editor-toolbar directory * Move PreviewButton into editor-toolbar * The time to refactor this is not quite yet here * Create tag-editor directory * Remove some of the uses of WithShortcut * Remove all uses of WithShortcut from editor package * Remove last uses of WithShortcut * Fix typo
79 lines
2.8 KiB
Svelte
79 lines
2.8 KiB
Svelte
<!--
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
-->
|
|
<script lang="ts">
|
|
import * as tr from "../../lib/ftl";
|
|
import IconButton from "../../components/IconButton.svelte";
|
|
import WithDropdown from "../../components/WithDropdown.svelte";
|
|
import DropdownMenu from "../../components/DropdownMenu.svelte";
|
|
import DropdownItem from "../../components/DropdownItem.svelte";
|
|
import Shortcut from "../../components/Shortcut.svelte";
|
|
import { withButton } from "../../components/helpers";
|
|
import { getPlatformString } from "../../lib/shortcuts";
|
|
import { wrapInternal } from "../../lib/wrap";
|
|
import { functionIcon } from "./icons";
|
|
import { getNoteEditor } from "../OldEditorAdapter.svelte";
|
|
import type { RichTextInputAPI } from "../rich-text-input";
|
|
|
|
const { activeInput, focusInRichText } = getNoteEditor();
|
|
$: richTextAPI = $activeInput as RichTextInputAPI;
|
|
|
|
async function surround(front: string, back: string): Promise<void> {
|
|
const element = await richTextAPI.element;
|
|
wrapInternal(element, front, back, false);
|
|
}
|
|
|
|
function onMathjaxInline(): void {
|
|
surround("<anki-mathjax focusonmount>", "</anki-mathjax>");
|
|
}
|
|
|
|
function onMathjaxBlock(): void {
|
|
surround('<anki-mathjax block="true" focusonmount>', "</anki-matjax>");
|
|
}
|
|
|
|
function onMathjaxChemistry(): void {
|
|
surround("<anki-mathjax focusonmount>\\ce{", "}</anki-mathjax>");
|
|
}
|
|
|
|
function onLatex(): void {
|
|
surround("[latex]", "[/latex]");
|
|
}
|
|
|
|
function onLatexEquation(): void {
|
|
surround("[$]", "[/$]");
|
|
}
|
|
|
|
function onLatexMathEnv(): void {
|
|
surround("[$$]", "[/$$]");
|
|
}
|
|
|
|
type LatexItem = [() => void, string, string];
|
|
|
|
const dropdownItems: LatexItem[] = [
|
|
[onMathjaxInline, "Control+M, M", tr.editingMathjaxInline()],
|
|
[onMathjaxBlock, "Control+M, E", tr.editingMathjaxBlock()],
|
|
[onMathjaxChemistry, "Control+M, C", tr.editingMathjaxChemistry()],
|
|
[onLatex, "Control+T, T", tr.editingLatex()],
|
|
[onLatexEquation, "Control+T, E", tr.editingLatexEquation()],
|
|
[onLatexMathEnv, "Control+T, M", tr.editingLatexMathEnv()],
|
|
];
|
|
|
|
$: disabled = !$focusInRichText;
|
|
</script>
|
|
|
|
<WithDropdown let:createDropdown>
|
|
<IconButton {disabled} on:mount={withButton(createDropdown)}>
|
|
{@html functionIcon}
|
|
</IconButton>
|
|
|
|
<DropdownMenu>
|
|
{#each dropdownItems as [callback, keyCombination, label]}
|
|
<DropdownItem on:click={callback}>
|
|
{label}
|
|
<span class="ps-1 float-end">{getPlatformString(keyCombination)}</span>
|
|
</DropdownItem>
|
|
<Shortcut {keyCombination} on:action={callback} />
|
|
{/each}
|
|
</DropdownMenu>
|
|
</WithDropdown>
|