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

Function resolveSourcePathForEmbed

src/code_embed.ts:480–517  ·  view source on GitHub ↗
(embedEl: HTMLElement, plugin: CodeSpacePlugin)

Source from the content-addressed store, hash-verified

478}
479
480function resolveSourcePathForEmbed(embedEl: HTMLElement, plugin: CodeSpacePlugin): string {
481 const rememberedSourcePath = getRememberedSourcePath(embedEl);
482 if (rememberedSourcePath) return rememberedSourcePath;
483
484 const ancestorSourcePath = resolveSourcePathFromAncestors(embedEl, plugin);
485 if (ancestorSourcePath) {
486 rememberSourcePath(embedEl, ancestorSourcePath);
487 return ancestorSourcePath;
488 }
489
490 // Use the containing leaf's file path (works across popout windows) instead of activeFile.
491 try {
492 let matchedPath = "";
493
494 plugin.app.workspace.iterateAllLeaves((leaf) => {
495 if (matchedPath) return;
496 const view = leaf.view as unknown as { file?: TFile; containerEl?: HTMLElement } | null;
497 const containerEl = view?.containerEl;
498 if (containerEl && containerEl.contains(embedEl)) {
499 const filePath = view?.file?.path;
500 if (filePath) {
501 matchedPath = filePath;
502 }
503 }
504 });
505
506 if (matchedPath) {
507 rememberSourcePath(embedEl, matchedPath);
508 return matchedPath;
509 }
510 } catch {
511 // Ignore and fall back.
512 }
513
514 const activePath = plugin.app.workspace.getActiveFile()?.path ?? "";
515 if (activePath) rememberSourcePath(embedEl, activePath);
516 return activePath;
517}
518
519function installEmbedObserverForDocument(doc: Document, docWindow: Window, plugin: CodeSpacePlugin) {
520 if (embedObserversByDoc.has(doc)) return;

Callers 5

processEmbedsMethod · 0.85
processCodeEmbedFunction · 0.85

Calls 3

getRememberedSourcePathFunction · 0.85
rememberSourcePathFunction · 0.85

Tested by

no test coverage detected