(view, { start, end })
| 24 | import { format, lex, minify, parse, parse_error_report } from "csskit/bundler"; |
| 25 | |
| 26 | function 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 | |
| 60 | class LoadCodeEvent extends Event { |
| 61 | constructor(sourcetext) { |
no test coverage detected