From a96c52b21e7e590bbdd70b80896780a446fa2e8b Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Mon, 13 Dec 2021 02:07:04 +0100 Subject: build: separate module for frontend This allows us to simplify the webpack configuration and the gradle build scripts. --- .../frontend/src/editor/semanticHighlighting.ts | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 subprojects/frontend/src/editor/semanticHighlighting.ts (limited to 'subprojects/frontend/src/editor/semanticHighlighting.ts') diff --git a/subprojects/frontend/src/editor/semanticHighlighting.ts b/subprojects/frontend/src/editor/semanticHighlighting.ts new file mode 100644 index 00000000..2aed421b --- /dev/null +++ b/subprojects/frontend/src/editor/semanticHighlighting.ts @@ -0,0 +1,24 @@ +import { RangeSet } from '@codemirror/rangeset'; +import type { TransactionSpec } from '@codemirror/state'; +import { Decoration } from '@codemirror/view'; + +import { decorationSetExtension } from './decorationSetExtension'; + +export interface IHighlightRange { + from: number; + + to: number; + + classes: string[]; +} + +const [setSemanticHighlightingInternal, semanticHighlighting] = decorationSetExtension(); + +export function setSemanticHighlighting(ranges: IHighlightRange[]): TransactionSpec { + const rangeSet = RangeSet.of(ranges.map(({ from, to, classes }) => Decoration.mark({ + class: classes.map((c) => `cmt-problem-${c}`).join(' '), + }).range(from, to)), true); + return setSemanticHighlightingInternal(rangeSet); +} + +export { semanticHighlighting }; -- cgit v1.2.3-54-g00ecf