mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-10 03:03:37 +02:00
@@ -21,6 +21,7 @@ import {
|
|||||||
import { lintKeymap } from '@codemirror/lint';
|
import { lintKeymap } from '@codemirror/lint';
|
||||||
|
|
||||||
import { searchKeymap } from '@codemirror/search';
|
import { searchKeymap } from '@codemirror/search';
|
||||||
|
import type { Extension } from '@codemirror/state';
|
||||||
import { EditorState } from '@codemirror/state';
|
import { EditorState } from '@codemirror/state';
|
||||||
import {
|
import {
|
||||||
crosshairCursor,
|
crosshairCursor,
|
||||||
@@ -73,6 +74,8 @@ export const syntaxHighlightStyle = HighlightStyle.define([
|
|||||||
|
|
||||||
const syntaxTheme = EditorView.theme({}, { dark: true });
|
const syntaxTheme = EditorView.theme({}, { dark: true });
|
||||||
|
|
||||||
|
const closeBracketsExts: Extension = [closeBrackets(), keymap.of([...closeBracketsKeymap])];
|
||||||
|
|
||||||
const syntaxExtensions: Record<NonNullable<EditorProps['language']>, LanguageSupport | null> = {
|
const syntaxExtensions: Record<NonNullable<EditorProps['language']>, LanguageSupport | null> = {
|
||||||
graphql: null,
|
graphql: null,
|
||||||
json: json(),
|
json: json(),
|
||||||
@@ -85,6 +88,8 @@ const syntaxExtensions: Record<NonNullable<EditorProps['language']>, LanguageSup
|
|||||||
markdown: markdown(),
|
markdown: markdown(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const closeBracketsFor: (keyof typeof syntaxExtensions)[] = ['json', 'javascript'];
|
||||||
|
|
||||||
export function getLanguageExtension({
|
export function getLanguageExtension({
|
||||||
language,
|
language,
|
||||||
useTemplating = false,
|
useTemplating = false,
|
||||||
@@ -110,7 +115,13 @@ export function getLanguageExtension({
|
|||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
const extraExtensions = language === 'url' ? [pathParametersPlugin(onClickPathParameter)] : [];
|
const extraExtensions: Extension[] =
|
||||||
|
language === 'url' ? [pathParametersPlugin(onClickPathParameter)] : [];
|
||||||
|
|
||||||
|
// Only close brackets on languages that need it
|
||||||
|
if (language && closeBracketsFor.includes(language)) {
|
||||||
|
extraExtensions.push(closeBracketsExts);
|
||||||
|
}
|
||||||
|
|
||||||
return twig({
|
return twig({
|
||||||
base,
|
base,
|
||||||
@@ -209,9 +220,8 @@ export const multiLineExtensions = ({ hideGutter }: { hideGutter?: boolean }) =>
|
|||||||
}),
|
}),
|
||||||
EditorState.allowMultipleSelections.of(true),
|
EditorState.allowMultipleSelections.of(true),
|
||||||
indentOnInput(),
|
indentOnInput(),
|
||||||
closeBrackets(),
|
|
||||||
rectangularSelection(),
|
rectangularSelection(),
|
||||||
crosshairCursor(),
|
crosshairCursor(),
|
||||||
highlightActiveLineGutter(),
|
highlightActiveLineGutter(),
|
||||||
keymap.of([...closeBracketsKeymap, ...searchKeymap, ...foldKeymap, ...lintKeymap]),
|
keymap.of([...searchKeymap, ...foldKeymap, ...lintKeymap]),
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user