MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / injectCanvasTaskCardWidgets

Function injectCanvasTaskCardWidgets

src/editor/TaskCardNoteDecorations.ts:641–689  ·  view source on GitHub ↗
(
	plugin: TaskNotesPlugin,
	options: { force?: boolean } = {}
)

Source from the content-addressed store, hash-verified

639}
640
641export function injectCanvasTaskCardWidgets(
642 plugin: TaskNotesPlugin,
643 options: { force?: boolean } = {}
644): void {
645 if (!plugin.settings.showTaskCardInNote) {
646 return;
647 }
648
649 for (const leaf of plugin.app.workspace.getLeavesOfType("canvas")) {
650 for (const node of getCanvasNodes(leaf)) {
651 const filePath = getCanvasNodeFilePath(node);
652 const contentEl = node.contentEl;
653 if (!filePath || !contentEl) {
654 continue;
655 }
656
657 const isEditing = isCanvasNodeEditing(node, contentEl);
658 const sourceEditor = contentEl.querySelector<HTMLElement>(
659 ".markdown-source-view, .cm-editor"
660 );
661 if (sourceEditor?.querySelector(`.${CSS_TASK_CARD_WIDGET}`)) {
662 continue;
663 }
664
665 const targetContainer = findCanvasEmbedTaskCardContainer(contentEl);
666 if (!isEditing && !targetContainer) {
667 continue;
668 }
669
670 if (!options.force && !canvasNodeNeedsWidgetRefresh(node, contentEl)) {
671 continue;
672 }
673
674 const task = plugin.cacheManager.getCachedTaskInfoSync(filePath);
675 removeTaskCardWidgets(contentEl);
676
677 if (!task) {
678 continue;
679 }
680
681 const widget = createTaskCardWidget(plugin, task);
682 if (isEditing) {
683 contentEl.insertBefore(widget, contentEl.firstChild);
684 } else if (targetContainer) {
685 insertAfterMetadataOrHeader(targetContainer, widget);
686 }
687 }
688 }
689}
690
691/**
692 * Setup reading mode handlers for task card widget

Callers 3

injectWidgetMethod · 0.85
debouncedCanvasRefreshFunction · 0.85

Calls 9

getCanvasNodesFunction · 0.85
getCanvasNodeFilePathFunction · 0.85
isCanvasNodeEditingFunction · 0.85
removeTaskCardWidgetsFunction · 0.85
createTaskCardWidgetFunction · 0.85
getCachedTaskInfoSyncMethod · 0.80

Tested by

no test coverage detected