(decorations, transaction)
| 21 | return Decoration.none; |
| 22 | }, |
| 23 | update(decorations, transaction) { |
| 24 | decorations = decorations.map(transaction.changes); |
| 25 | const highlights = []; |
| 26 | for (const effect of transaction.effects) { |
| 27 | if (!effect.is(setHighlight)) { |
| 28 | continue; |
| 29 | } |
| 30 | const query = effect.value; |
| 31 | if (query === "") { |
| 32 | continue; |
| 33 | } |
| 34 | const pattern = new RegExp(escapeRegExp(query), "g"); |
| 35 | const cursor = transaction.startState.doc.iter(); |
| 36 | let position = 0; |
| 37 | while (!cursor.next().done) { |
| 38 | const line = cursor.value; |
| 39 | let match; |
| 40 | while ((match = pattern.exec(line))) { |
| 41 | const from = position + match.index; |
| 42 | const to = from + match[0].length; |
| 43 | if (from - to === 0) { |
| 44 | // We've got an empty match, bail on this line. |
| 45 | break; |
| 46 | } |
| 47 | highlights.push(highlightMark.range(from, to)); |
| 48 | } |
| 49 | position += line.length; |
| 50 | } |
| 51 | } |
| 52 | decorations = decorations.update({ |
| 53 | add: highlights, |
| 54 | // Clear the pre-existing highlights |
| 55 | filter: () => false, |
| 56 | }); |
| 57 | return decorations; |
| 58 | }, |
| 59 | provide: (facet) => EditorView.decorations.from(facet), |
| 60 | }); |
| 61 |
no test coverage detected