blob: 2c1bd67d3360074fe22f2c528c1278412c9eb5b6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import { RangeSet, type TransactionSpec } from '@codemirror/state';
import { Decoration } from '@codemirror/view';
import defineDecorationSetExtension from './defineDecorationSetExtension';
export interface IHighlightRange {
from: number;
to: number;
classes: string[];
}
const [setSemanticHighlightingInternal, semanticHighlighting] =
defineDecorationSetExtension();
export function setSemanticHighlighting(
ranges: IHighlightRange[],
): TransactionSpec {
const rangeSet = RangeSet.of(
ranges.map(({ from, to, classes }) =>
Decoration.mark({
class: classes.map((c) => `tok-problem-${c}`).join(' '),
}).range(from, to),
),
true,
);
return setSemanticHighlightingInternal(rangeSet);
}
export default semanticHighlighting;
|