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

Function createTaskLinkViewPlugin

src/editor/TaskLinkOverlay.ts:39–215  ·  view source on GitHub ↗
(plugin: TaskNotesPlugin)

Source from the content-addressed store, hash-verified

37
38// Create a ViewPlugin factory that takes the plugin as a parameter
39export function createTaskLinkViewPlugin(plugin: TaskNotesPlugin) {
40 // Track widget instances for updates
41 const activeWidgets = new Map<string, TaskLinkWidget>();
42 // Fallback cache keyed by resolvedPath only — survives position shifts and activeWidgets.clear()
43 const lastKnownWidgets = new Map<string, TaskLinkWidget>();
44
45 return ViewPlugin.fromClass(
46 class {
47 decorations: DecorationSet;
48 private eventListeners: EventRef[] = [];
49 private view: EditorView;
50
51 constructor(view: EditorView) {
52 this.view = view;
53 this.decorations = this.buildDecorations(view);
54 this.setupEventListeners();
55 }
56
57 destroy() {
58 // Clean up event listeners
59 this.eventListeners.forEach((listener) => {
60 plugin.emitter.offref(listener);
61 });
62 this.eventListeners = [];
63 }
64
65 setupEventListeners() {
66 // Listen for data changes that might affect task link widgets
67 const dataChangeListener = plugin.emitter.on(EVENT_DATA_CHANGED, () => {
68 this.refreshDecorations();
69 });
70
71 const taskUpdateListener = plugin.emitter.on(EVENT_TASK_UPDATED, () => {
72 this.refreshDecorations();
73 });
74
75 const taskDeleteListener = plugin.emitter.on(
76 EVENT_TASK_DELETED,
77 (data?: { path?: string }) => {
78 if (data?.path) {
79 lastKnownWidgets.delete(data.path);
80 }
81 this.refreshDecorations();
82 }
83 );
84
85 const dateChangeListener = plugin.emitter.on(EVENT_DATE_CHANGED, () => {
86 lastKnownWidgets.clear();
87 this.refreshDecorations();
88 });
89
90 // Listen for settings changes
91 const settingsChangeListener = plugin.emitter.on("settings-changed", () => {
92 this.refreshDecorations();
93 });
94
95 this.eventListeners.push(
96 dataChangeListener,

Callers 1

createTaskLinkOverlayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected