diff options
Diffstat (limited to 'language-web/src/main/js/editor/semanticHighlighting.ts')
-rw-r--r-- | language-web/src/main/js/editor/semanticHighlighting.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/language-web/src/main/js/editor/semanticHighlighting.ts b/language-web/src/main/js/editor/semanticHighlighting.ts new file mode 100644 index 00000000..2d6804f8 --- /dev/null +++ b/language-web/src/main/js/editor/semanticHighlighting.ts | |||
@@ -0,0 +1,34 @@ | |||
1 | import { StateEffect, StateField, TransactionSpec } from '@codemirror/state'; | ||
2 | import { EditorView, Decoration, DecorationSet } from '@codemirror/view'; | ||
3 | |||
4 | const setSemanticHighlightingEffect = StateEffect.define<DecorationSet>(); | ||
5 | |||
6 | export function setSemanticHighlighting(decorations: DecorationSet): TransactionSpec { | ||
7 | return { | ||
8 | effects: [ | ||
9 | setSemanticHighlightingEffect.of(decorations), | ||
10 | ], | ||
11 | }; | ||
12 | } | ||
13 | |||
14 | export const semanticHighlighting = StateField.define<DecorationSet>({ | ||
15 | create() { | ||
16 | return Decoration.none; | ||
17 | }, | ||
18 | update(currentDecorations, transaction) { | ||
19 | let newDecorations: DecorationSet | null = null; | ||
20 | transaction.effects.forEach((effect) => { | ||
21 | if (effect.is(setSemanticHighlightingEffect)) { | ||
22 | newDecorations = effect.value; | ||
23 | } | ||
24 | }); | ||
25 | if (newDecorations === null) { | ||
26 | if (transaction.docChanged) { | ||
27 | return currentDecorations.map(transaction.changes); | ||
28 | } | ||
29 | return currentDecorations; | ||
30 | } | ||
31 | return newDecorations; | ||
32 | }, | ||
33 | provide: (f) => EditorView.decorations.from(f), | ||
34 | }); | ||