mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 00:36:38 -04:00

* Refactor editor css, fix editor button highlight - Avoid using webview.css - Move more buttons css into button_mixins * Fix DropdownItem appearance * Fix the visuals of tags * Make dropdown font slightly smaller * Give SelectOption a background color * Move some css from deck-options-base to CardStateCustomizer * Avoid using core.scss for CardStats * Avoid using sass/core in congrats package * Inline core.scss into webview.scss * Include fusion-vars for base.scss * need to keep core.scss around for now (dae)
81 lines
2.2 KiB
Svelte
81 lines
2.2 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 { onMount, createEventDispatcher } from "svelte";
|
|
import { ChangeTimer } from "../change-timer";
|
|
import { CodeMirror, latex, baseOptions } from "../code-mirror";
|
|
|
|
export let initialValue: string;
|
|
|
|
const codeMirrorOptions = {
|
|
mode: latex,
|
|
...baseOptions,
|
|
};
|
|
|
|
let codeMirror: CodeMirror.EditorFromTextArea;
|
|
const changeTimer = new ChangeTimer();
|
|
const dispatch = createEventDispatcher();
|
|
|
|
function onInput() {
|
|
dispatch("update", { mathjax: codeMirror.getValue() });
|
|
|
|
/* changeTimer.schedule( */
|
|
/* () => dispatch("update", { mathjax: codeMirror.getValue() }), */
|
|
/* 400 */
|
|
/* ); */
|
|
}
|
|
|
|
function onBlur() {
|
|
changeTimer.fireImmediately();
|
|
dispatch("codemirrorblur");
|
|
}
|
|
|
|
function openCodemirror(textarea: HTMLTextAreaElement): void {
|
|
codeMirror = CodeMirror.fromTextArea(textarea, codeMirrorOptions);
|
|
codeMirror.on("change", onInput);
|
|
codeMirror.on("blur", onBlur);
|
|
}
|
|
|
|
let textarea: HTMLTextAreaElement;
|
|
|
|
onMount(() => {
|
|
codeMirror.focus();
|
|
codeMirror.setCursor(codeMirror.lineCount(), 0);
|
|
|
|
const codeMirrorElement = textarea.nextElementSibling!;
|
|
codeMirrorElement.classList.add("mathjax-editor");
|
|
});
|
|
</script>
|
|
|
|
<div
|
|
on:click|stopPropagation
|
|
on:focus|stopPropagation
|
|
on:focusin|stopPropagation
|
|
on:keydown|stopPropagation
|
|
on:keyup|stopPropagation
|
|
on:mousedown|preventDefault|stopPropagation
|
|
on:mouseup|stopPropagation
|
|
on:paste|stopPropagation
|
|
>
|
|
<!-- TODO no focusin for now, as EditingArea will defer to Editable/Codable -->
|
|
<textarea
|
|
bind:this={textarea}
|
|
value={initialValue}
|
|
on:input={onInput}
|
|
use:openCodemirror
|
|
/>
|
|
</div>
|
|
|
|
<style lang="scss">
|
|
div :global(.mathjax-editor) {
|
|
border-radius: 0;
|
|
border-width: 0 1px;
|
|
border-color: var(--medium-border);
|
|
|
|
height: auto;
|
|
border-radius: 0 0 5px 5px;
|
|
padding: 6px 0;
|
|
}
|
|
</style>
|