anki/ts/editor/code-mirror.ts
Henrik Giesel 4360fd16fb
Use default colors for CodeMirror in light theme Anki (#1578)
Refactor PlainTextInput

Put CodeMirror themes into variables
2022-01-10 12:51:50 +10:00

56 lines
1.5 KiB
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import "codemirror/lib/codemirror.css";
import "codemirror/addon/fold/foldgutter.css";
import "codemirror/theme/monokai.css";
import CodeMirror from "codemirror";
import "codemirror/mode/htmlmixed/htmlmixed";
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";
import "codemirror/addon/edit/closetag";
import "codemirror/addon/display/placeholder";
export { CodeMirror };
export const latex = {
name: "stex",
inMathMode: true,
};
export const htmlanki = {
name: "htmlmixed",
tags: {
"anki-mathjax": [[null, null, latex]],
},
};
export const lightCodeMirrorTheme = "default";
export const darkCodeMirrorTheme = "monokai";
export const baseOptions: CodeMirror.EditorConfiguration = {
theme: lightCodeMirrorTheme,
lineWrapping: true,
matchTags: { bothTags: true },
autoCloseTags: true,
extraKeys: { Tab: false, "Shift-Tab": false },
tabindex: 0,
viewportMargin: Infinity,
lineWiseCopyCut: false,
};
export const gutterOptions: CodeMirror.EditorConfiguration = {
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
lineNumbers: true,
foldGutter: true,
};
export function focusAndCaretAfter(editor: CodeMirror.Editor): void {
editor.focus();
editor.setCursor(editor.lineCount(), 0);
}