MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / buildDecos

Method buildDecos

src/sidebarApps/searchInFiles/cmResultView.js:252–324  ·  view source on GitHub ↗
(view)

Source from the content-addressed store, hash-verified

250 }
251
252 buildDecos(view) {
253 const builder = [];
254 if (isGhostText) return Decoration.none;
255 let searchRegex = null;
256 if (typeof getRegex === "function") {
257 const r = getRegex();
258 if (r && r.source) {
259 const flags = (r.ignoreCase ? "i" : "") + "g";
260 try {
261 searchRegex = new RegExp(r.source, flags);
262 } catch {}
263 }
264 }
265 const words = searchRegex ? [] : (getWords?.() || []).filter(Boolean);
266
267 let wordRegex = null;
268 if (!searchRegex && words.length) {
269 const escaped = words
270 .map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
271 .join("|");
272 try {
273 wordRegex = new RegExp(escaped, "g");
274 } catch {}
275 }
276 // Add match highlights only on visible lines to keep it fast
277 const matcher = searchRegex || wordRegex;
278 if (matcher) {
279 for (const { from, to } of view.visibleRanges) {
280 let pos = from;
281 while (pos <= to) {
282 const line = view.state.doc.lineAt(pos);
283 const text = line.text;
284 if (text && text.charCodeAt(0) === 9) {
285 const lineNumberMatch = text.match(/^\t\d+: /);
286 const searchStart = lineNumberMatch
287 ? lineNumberMatch[0].length
288 : 0;
289 if (lineNumberMatch) {
290 builder.push(
291 Decoration.mark({
292 class: "cm-resultLineNumber",
293 }).range(
294 line.from + 1,
295 line.from + lineNumberMatch[0].length,
296 ),
297 );
298 }
299 matcher.lastIndex = 0;
300 let m;
301 while ((m = matcher.exec(text))) {
302 if (m.index < searchStart) {
303 if (m.index === matcher.lastIndex) matcher.lastIndex++;
304 continue;
305 }
306 const fromPos = line.from + m.index;
307 const toPos = fromPos + m[0].length;
308 builder.push(
309 Decoration.mark({ class: "cm-match" }).range(

Callers 2

constructorMethod · 0.80
updateMethod · 0.80

Calls 2

setMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected