Browse Source

update

main
wangshaoping 1 year ago
parent
commit
7bdf9f5dcc
  1. 72
      io.sc.platform.core.frontend/src/platform/components/widget/codemirror/Util.ts

72
io.sc.platform.core.frontend/src/platform/components/widget/codemirror/Util.ts

@ -0,0 +1,72 @@
import {
EditorView,
lineNumbers,
highlightActiveLineGutter,
highlightSpecialChars,
drawSelection,
dropCursor,
rectangularSelection,
crosshairCursor,
highlightActiveLine,
keymap,
} from '@codemirror/view';
import { EditorState } from '@codemirror/state';
import { foldGutter, indentOnInput, syntaxHighlighting, defaultHighlightStyle, bracketMatching, foldKeymap } from '@codemirror/language';
import { history, defaultKeymap, historyKeymap } from '@codemirror/commands';
import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
import { closeBrackets, autocompletion, closeBracketsKeymap, completionKeymap } from '@codemirror/autocomplete';
import { lintKeymap } from '@codemirror/lint';
import { html } from '@codemirror/lang-html';
import { java } from '@codemirror/lang-java';
import { javascript } from '@codemirror/lang-javascript';
import { json } from '@codemirror/lang-json';
import { sql } from '@codemirror/lang-sql';
import { xml } from '@codemirror/lang-xml';
export const basicSetup = [
//lineNumbers(),
highlightActiveLineGutter(),
highlightSpecialChars(),
history(),
//foldGutter(),
drawSelection(),
dropCursor(),
EditorState.allowMultipleSelections.of(true),
indentOnInput(),
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
bracketMatching(),
closeBrackets(),
autocompletion(),
rectangularSelection(),
crosshairCursor(),
//highlightActiveLine(),
highlightSelectionMatches(),
keymap.of([...closeBracketsKeymap, ...defaultKeymap, ...searchKeymap, ...historyKeymap, ...foldKeymap, ...completionKeymap, ...lintKeymap]),
];
export const basicTheme = () => {
return EditorView.theme({
'.cm-editor': {
outline: 'none !important',
},
});
};
export const getLanguage = (lang: string) => {
if (lang === 'html') {
return html();
} else if (lang === 'java') {
return java();
} else if (lang === 'javascript') {
return javascript();
} else if (lang === 'json') {
return json();
} else if (lang === 'sql') {
return sql();
} else if (lang === 'xml') {
return xml();
} else {
return json();
}
};
Loading…
Cancel
Save