Files
triggerdotdev--trigger.dev/apps/webapp/app/components/code/codeMirrorSetup.ts
T
Saadi Myftija fab565256e Allow empty payloads in test runs (#1962)
* Allow empty payloads in test runs

* Expose a basic linter configs in the code editor component

* Touch up the linting error elements in the code editor component
2025-04-22 16:23:52 +01:00

52 lines
1.2 KiB
TypeScript

import { closeBrackets } from "@codemirror/autocomplete";
import { indentWithTab } from "@codemirror/commands";
import { bracketMatching } from "@codemirror/language";
import { lintKeymap } from "@codemirror/lint";
import { highlightSelectionMatches } from "@codemirror/search";
import { Prec, type Extension } from "@codemirror/state";
import {
drawSelection,
dropCursor,
highlightActiveLine,
highlightActiveLineGutter,
highlightSpecialChars,
keymap,
lineNumbers,
} from "@codemirror/view";
export function getEditorSetup(showLineNumbers = true, showHighlights = true): Array<Extension> {
const options = [
drawSelection(),
dropCursor(),
bracketMatching(),
closeBrackets(),
Prec.highest(
keymap.of([
{
key: "Mod-Enter",
run: () => {
return true;
},
preventDefault: false,
},
])
),
keymap.of([indentWithTab, ...lintKeymap]),
];
if (showLineNumbers) {
options.push(lineNumbers());
}
if (showHighlights) {
options.push([
highlightActiveLineGutter(),
highlightSpecialChars(),
highlightActiveLine(),
highlightSelectionMatches(),
]);
}
return options;
}