MCPcopy Create free account
hub / github.com/csskit/csskit / createHighlightEffect

Function createHighlightEffect

website/script/index.js:26–58  ·  view source on GitHub ↗
(view, { start, end })

Source from the content-addressed store, hash-verified

24import { format, lex, minify, parse, parse_error_report } from "csskit/bundler";
25
26function createHighlightEffect(view, { start, end }) {
27 let range = EditorSelection.range(start, end);
28 const highlighter = Decoration.mark({ class: "cm-highlight" });
29 if (!start && !end) return;
30 const addHighlight = StateEffect.define({
31 map: ({ from, to }, change) => ({
32 from: change.mapPos(from),
33 to: change.mapPos(to),
34 }),
35 });
36 const highlightField = StateField.define({
37 create() {
38 return Decoration.none;
39 },
40 update(highlights, tr) {
41 highlights = RangeSet.empty;
42 for (let e of tr.effects) {
43 if (e.is(addHighlight)) {
44 highlights = highlights.update({
45 add: [highlighter.range(e.value.from, e.value.to)],
46 });
47 }
48 }
49 return highlights;
50 },
51 provide: (f) => EditorView.decorations.from(f),
52 });
53 const effects = [addHighlight.of(range)];
54 if (!view.state.field(highlightField, false)) {
55 effects.push(StateEffect.appendConfig.of([highlightField, csskitLight]));
56 }
57 view.dispatch({ effects });
58}
59
60class LoadCodeEvent extends Event {
61 constructor(sourcetext) {

Callers 2

handleEventMethod · 0.85
handleEventMethod · 0.85

Calls 2

defineMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected