MCPcopy Index your code
hub / github.com/UNLINEARITY/Obsidian-CodeSpace / scheduleProcessCodeEmbed

Function scheduleProcessCodeEmbed

src/code_embed.ts:586–608  ·  view source on GitHub ↗
(embedEl: HTMLElement, plugin: CodeSpacePlugin, sourcePath: string)

Source from the content-addressed store, hash-verified

584}
585
586function scheduleProcessCodeEmbed(embedEl: HTMLElement, plugin: CodeSpacePlugin, sourcePath: string) {
587 // Obsidian may update embed attributes shortly after insertion; debounce to avoid duplicate renders.
588 rememberSourcePath(embedEl, sourcePath);
589 pendingEmbedRequests.set(embedEl, { sourcePath });
590
591 const ownerWindow = embedEl.ownerDocument.defaultView ?? window;
592 const existing = pendingEmbedTimers.get(embedEl);
593 if (existing) ownerWindow.clearTimeout(existing);
594
595 const timer = ownerWindow.setTimeout(() => {
596 pendingEmbedTimers.delete(embedEl);
597 const req = pendingEmbedRequests.get(embedEl);
598 pendingEmbedRequests.delete(embedEl);
599
600 // Token-gate async read/render so stale runs can't overwrite newer renders (prevents flicker).
601 const token = (embedRenderTokens.get(embedEl) ?? 0) + 1;
602 embedRenderTokens.set(embedEl, token);
603
604 void processCodeEmbed(embedEl, plugin, req?.sourcePath ?? sourcePath, token);
605 }, 40);
606
607 pendingEmbedTimers.set(embedEl, timer);
608}
609
610export function registerCodeEmbedProcessor(plugin: CodeSpacePlugin) {
611 // Install observer for the main window document to catch any embeds that the post processor misses.

Callers 5

processEmbedsMethod · 0.85
queueCodeEmbedsInElementFunction · 0.85

Calls 2

rememberSourcePathFunction · 0.85
processCodeEmbedFunction · 0.85

Tested by

no test coverage detected