MCPcopy
hub / github.com/marktext/marktext / _updateMatches

Method _updateMatches

packages/muya/src/search/index.ts:20–52  ·  view source on GitHub ↗
(isClear = false)

Source from the content-addressed store, hash-verified

18 constructor(public muya: Muya) {}
19
20 private _updateMatches(isClear = false) {
21 const { matches, index } = this;
22 let i;
23 const len = matches.length;
24 const matchesMap = new Map<Content, IHighlight[]>();
25
26 for (i = 0; i < len; i++) {
27 const { block, start, end } = matches[i];
28 const active = i === index;
29 const highlight: IHighlight = { start, end, active };
30 const highlights = matchesMap.get(block);
31
32 if (matchesMap.has(block) && Array.isArray(highlights)) {
33 highlights.push(highlight);
34 matchesMap.set(block, highlights);
35 }
36 else {
37 matchesMap.set(block, [highlight]);
38 }
39 }
40
41 for (const [block, highlights] of matchesMap.entries()) {
42 const isActive = highlights.some(h => h.active);
43
44 block.update(undefined, isClear ? [] : highlights);
45
46 if (block.parent?.active && !isActive)
47 block.blurHandler();
48
49 if (isActive && !isClear)
50 block.focusHandler();
51 }
52 }
53
54 private _innerReplace(matches: IMatch[], value: string) {
55 if (!matches.length)

Callers 2

findMethod · 0.95
searchMethod · 0.95

Calls 6

getMethod · 0.80
pushMethod · 0.80
focusHandlerMethod · 0.80
hasMethod · 0.65
updateMethod · 0.45
blurHandlerMethod · 0.45

Tested by

no test coverage detected