MCPcopy
hub / github.com/callumalpass/tasknotes / injectReadingModeWidget

Function injectReadingModeWidget

src/editor/TaskCardNoteDecorations.ts:561–639  ·  view source on GitHub ↗

* Inject task card widget into reading mode view

(
	leaf: WorkspaceLeaf,
	plugin: TaskNotesPlugin,
	context?: ReadingModeInjectionContext
)

Source from the content-addressed store, hash-verified

559 * Inject task card widget into reading mode view
560 */
561async function injectReadingModeWidget(
562 leaf: WorkspaceLeaf,
563 plugin: TaskNotesPlugin,
564 context?: ReadingModeInjectionContext
565): Promise<void> {
566 const view = leaf.view;
567 if (!(view instanceof MarkdownView) || view.getMode() !== "preview") {
568 return;
569 }
570
571 if (shouldSkipMarkdownWidgetLeaf(leaf)) {
572 return;
573 }
574
575 const file = view.file;
576 if (!file) {
577 return;
578 }
579
580 // Check if task card widget is enabled
581 if (!plugin.settings.showTaskCardInNote) {
582 return;
583 }
584
585 // Get task info for this file
586 const task = plugin.cacheManager.getCachedTaskInfoSync(file.path);
587 if (!task) {
588 // Not a task note - remove any existing widgets
589 try {
590 const previewView = view.previewMode;
591 const containerEl = previewView.containerEl;
592 removeTaskCardWidgets(containerEl);
593 } catch (error) {
594 tasknotesLogger.debug("[TaskNotes] Error cleaning up task card in reading mode:", {
595 category: "persistence",
596 operation: "cleaning-up-task-card-reading-mode",
597 error: error,
598 });
599 }
600 return;
601 }
602
603 try {
604 // Remove any existing widgets first
605 const previewView = view.previewMode;
606 const containerEl = previewView.containerEl;
607 removeTaskCardWidgets(containerEl);
608
609 // Create the widget
610 const widget = createTaskCardWidget(plugin, task);
611 if (context && !context.isCurrent()) {
612 widget.component?.unload();
613 widget.remove();
614 return;
615 }
616
617 // Find the markdown-preview-sizer
618 // RISK: Relies on Obsidian's internal DOM structure

Callers 1

scheduleInjectionFunction · 0.70

Calls 10

removeTaskCardWidgetsFunction · 0.85
createTaskCardWidgetFunction · 0.85
getCachedTaskInfoSyncMethod · 0.80
debugMethod · 0.80
isCurrentMethod · 0.80
warnMethod · 0.80
errorMethod · 0.80
unloadMethod · 0.65

Tested by

no test coverage detected