ConceptPortal-public/rsconcept/frontend/src/components/RSInput/bracketMatching.ts
Ivan 91dbd0e88f
Some checks are pending
Frontend CI / build (22.x) (push) Waiting to run
F: Rework colors using tailwind configs
2024-12-17 00:05:45 +03:00

30 lines
849 B
TypeScript

import { bracketMatching, MatchResult } from '@codemirror/language';
import { Decoration, EditorView } from '@codemirror/view';
import { BRACKETS_THEME } from '@/styling/color';
const matchingMark = Decoration.mark({ class: 'cc-matchingBracket' });
const nonMatchingMark = Decoration.mark({ class: 'cc-nonmatchingBracket' });
function bracketRender(match: MatchResult) {
const decorations = [];
const mark = match.matched ? matchingMark : nonMatchingMark;
decorations.push(mark.range(match.start.from, match.start.to));
if (match.end) {
decorations.push(mark.range(match.end.from, match.end.to));
}
return decorations;
}
const theme = EditorView.baseTheme(BRACKETS_THEME);
export function ccBracketMatching() {
return [
bracketMatching({
renderMatch: bracketRender,
brackets: '{}[]()'
}),
theme
];
}