2021-08-06 16:52:34 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
|
|
|
<script lang="typescript">
|
2021-08-06 17:40:27 +02:00
|
|
|
import { onMount, createEventDispatcher } from "svelte";
|
|
|
|
|
2021-08-06 16:52:34 +02:00
|
|
|
import * as CodeMirror from "codemirror/lib/codemirror";
|
|
|
|
import "codemirror/mode/stex/stex";
|
|
|
|
import "codemirror/addon/fold/foldcode";
|
|
|
|
import "codemirror/addon/fold/foldgutter";
|
|
|
|
import "codemirror/addon/fold/xml-fold";
|
|
|
|
import "codemirror/addon/edit/matchtags.js";
|
|
|
|
import "codemirror/addon/edit/closetag.js";
|
|
|
|
|
|
|
|
export let initialValue: string;
|
|
|
|
|
|
|
|
const latex = {
|
|
|
|
name: "stex",
|
|
|
|
inMathMode: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
const codeMirrorOptions = {
|
|
|
|
mode: latex,
|
|
|
|
theme: "monokai",
|
|
|
|
/* lineNumbers: true, */
|
|
|
|
/* lineWrapping: true, */
|
|
|
|
/* foldGutter: true, */
|
|
|
|
/* gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"], */
|
|
|
|
/* matchTags: { bothTags: true }, */
|
|
|
|
/* extraKeys: { Tab: false, "Shift-Tab": false }, */
|
|
|
|
/* viewportMargin: Infinity, */
|
|
|
|
/* lineWiseCopyCut: false, */
|
|
|
|
/* autofocus: true, */
|
|
|
|
};
|
|
|
|
|
|
|
|
let codeMirror: CodeMirror;
|
|
|
|
|
|
|
|
function openCodemirror(textarea: HTMLTextAreaElement): void {
|
|
|
|
codeMirror = CodeMirror.fromTextArea(textarea, codeMirrorOptions);
|
|
|
|
codeMirror.setCursor(codeMirror.lineCount(), 0);
|
|
|
|
}
|
|
|
|
|
2021-08-06 17:40:27 +02:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
let textarea: HTMLTextAreaElement;
|
|
|
|
|
|
|
|
onMount(() => textarea.focus());
|
|
|
|
|
|
|
|
function onInput() {
|
|
|
|
dispatch("update", { mathjax: textarea.value });
|
2021-08-06 16:52:34 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- <textarea bind:value use:openCodemirror /> -->
|
|
|
|
<div on:click|stopPropagation on:focus|stopPropagation on:keydown|stopPropagation>
|
2021-08-06 17:21:47 +02:00
|
|
|
<!-- TODO no focusin for now, as EditingArea will defer to Editable/Codable -->
|
2021-08-06 16:52:34 +02:00
|
|
|
<textarea
|
2021-08-06 17:40:27 +02:00
|
|
|
bind:this={textarea}
|
2021-08-06 16:52:34 +02:00
|
|
|
value={initialValue}
|
|
|
|
on:mouseup|preventDefault|stopPropagation
|
2021-08-06 17:40:27 +02:00
|
|
|
on:keyup|stopPropagation
|
2021-08-06 16:52:34 +02:00
|
|
|
on:click|stopPropagation
|
|
|
|
on:focusin|stopPropagation
|
2021-08-06 17:40:27 +02:00
|
|
|
on:input={onInput}
|
2021-08-06 16:52:34 +02:00
|
|
|
/>
|
|
|
|
</div>
|