// based on https://github.com/codemirror/basic-setup/blob/main/src/codemirror.ts import { keymap, highlightSpecialChars, drawSelection, highlightActiveLine, dropCursor, rectangularSelection, crosshairCursor, lineNumbers, highlightActiveLineGutter, } from '@codemirror/view'; import { EditorState, type Extension } from '@codemirror/state'; import { defaultHighlightStyle, syntaxHighlighting, indentOnInput, bracketMatching, foldGutter, foldKeymap, } from '@codemirror/language'; import { defaultKeymap, history, historyKeymap } from '@codemirror/commands'; import { searchKeymap, highlightSelectionMatches } from '@codemirror/search'; import { autocompletion, completionKeymap, closeBrackets, closeBracketsKeymap, } from '@codemirror/autocomplete'; import { lintKeymap } from '@codemirror/lint'; // (The superfluous function calls around the list of extensions work // around current limitations in tree-shaking software.) /// This is an extension value that just pulls together a number of /// extensions that you might want in a basic editor. It is meant as a /// convenient helper to quickly set up CodeMirror without installing /// and importing a lot of separate packages. /// /// Specifically, it includes... /// /// - [the default command bindings](#commands.defaultKeymap) /// - [line numbers](#view.lineNumbers) /// - [special character highlighting](#view.highlightSpecialChars) /// - [the undo history](#commands.history) /// - [a fold gutter](#language.foldGutter) /// - [custom selection drawing](#view.drawSelection) /// - [drop cursor](#view.dropCursor) /// - [multiple selections](#state.EditorState^allowMultipleSelections) /// - [reindentation on input](#language.indentOnInput) /// - [the default highlight style](#language.defaultHighlightStyle) (as fallback) /// - [bracket matching](#language.bracketMatching) /// - [bracket closing](#autocomplete.closeBrackets) /// - [autocompletion](#autocomplete.autocompletion) /// - [rectangular selection](#view.rectangularSelection) and [crosshair cursor](#view.crosshairCursor) /// - [active line highlighting](#view.highlightActiveLine) /// - [active line gutter highlighting](#view.highlightActiveLineGutter) /// - [selection match highlighting](#search.highlightSelectionMatches) /// - [search](#search.searchKeymap) /// - [linting](#lint.lintKeymap) /// /// (You'll probably want to add some language package to your setup /// too.) /// /// This extension does not allow customization. The idea is that, /// once you decide you want to configure your editor more precisely, /// you take this package's source (which is just a bunch of imports /// and an array literal), copy it into your own code, and adjust it /// as desired. export const basicSetup: Extension = (() => [ // 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, ]), ])(); /// A minimal set of extensions to create a functional editor. Only /// includes [the default keymap](#commands.defaultKeymap), [undo /// history](#commands.history), [special character /// highlighting](#view.highlightSpecialChars), [custom selection /// drawing](#view.drawSelection), and [default highlight /// style](#language.defaultHighlightStyle). export const minimalSetup: Extension = (() => [ highlightSpecialChars(), history(), drawSelection(), syntaxHighlighting(defaultHighlightStyle, { fallback: true }), keymap.of([...defaultKeymap, ...historyKeymap]), ])(); export { EditorView } from '@codemirror/view'; export { lineNumbers, closeBrackets };