* Inject task card widget into reading mode view
( leaf: WorkspaceLeaf, plugin: TaskNotesPlugin, context?: ReadingModeInjectionContext )
| 559 | * Inject task card widget into reading mode view |
| 560 | */ |
| 561 | async 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 |
no test coverage detected