MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / update

Function update

console/src/components/CommandBlock/highlightExt.ts:23–58  ·  view source on GitHub ↗
(decorations, transaction)

Source from the content-addressed store, hash-verified

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

Callers 5

initMethod · 0.85
update_gtMethod · 0.85
update_geMethod · 0.85
debug_editMethod · 0.85
debug_deleteMethod · 0.85

Calls 8

escapeRegExpFunction · 0.90
isMethod · 0.80
execMethod · 0.80
mapMethod · 0.45
iterMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected