1 changed files with 72 additions and 0 deletions
@ -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…
Reference in new issue