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

* NF: replace `disabled` by `enabled` This allows to remove the negations and, in my opinion, make the code easier to understand and edit. * Cloze button get disabled outside of cloze field More specifically, if the user focus in a field that is not a cloze field, the button are still there but appear as disabled. The shortcut instead of adding the cloze context shows an alert explaining why this can't be done. While this message is already displayed when the user tries to add a note with cloze in non-cloze field, I suspect it will save time to stop the user as soon as possible from making mistake. This should make very clear what is authorized and what is not. It'll also be a reminder of whether the current field is a cloze or not. In order to do this, I added a back-end method (that I expect we may reuse in ankidroid) to get the index of the fields used in cloze. This set is sent to the note editor, which propagates it where needed. In mathjax, the cloze symbol is removed when the selected field is not a cloze field.
27 lines
845 B
Svelte
27 lines
845 B
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 { wrapInternal } from "@tslib/wrap";
|
|
|
|
import ClozeButtons from "../ClozeButtons.svelte";
|
|
import { context as noteEditorContext } from "../NoteEditor.svelte";
|
|
import type { RichTextInputAPI } from "../rich-text-input";
|
|
|
|
const { focusedInput } = noteEditorContext.get();
|
|
|
|
$: richTextAPI = $focusedInput as RichTextInputAPI;
|
|
|
|
async function onSurround({ detail }): Promise<void> {
|
|
if (!richTextAPI.isClozeField) {
|
|
return;
|
|
}
|
|
const richText = await richTextAPI.element;
|
|
const { prefix, suffix } = detail;
|
|
|
|
wrapInternal(richText, prefix, suffix, false);
|
|
}
|
|
</script>
|
|
|
|
<ClozeButtons on:surround={onSurround} />
|