blob: 2aed421b224ba84bba5d944db73695a8d116433c (
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
|
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 };
|