* Handle file change - emit events for listeners
(file: TFile, cache: unknown)
| 164 | * Handle file change - emit events for listeners |
| 165 | */ |
| 166 | private async handleFileChanged(file: TFile, cache: unknown): Promise<void> { |
| 167 | let updatedTask: TaskInfo | null = null; |
| 168 | let filterIndexChanged = false; |
| 169 | |
| 170 | if (cache && typeof cache === "object" && "frontmatter" in cache) { |
| 171 | const frontmatter = (cache as { frontmatter?: unknown }).frontmatter; |
| 172 | if (frontmatter && this.isTaskFile(frontmatter)) { |
| 173 | const metadataTaskInfo = this.extractTaskInfoFromNative(file.path, frontmatter); |
| 174 | const pendingTaskInfo = this.getPendingTaskInfo(file.path); |
| 175 | if ( |
| 176 | pendingTaskInfo && |
| 177 | this.shouldUsePendingTaskInfo(pendingTaskInfo, metadataTaskInfo) |
| 178 | ) { |
| 179 | updatedTask = pendingTaskInfo; |
| 180 | } else { |
| 181 | this.pendingTaskInfoByPath.delete(file.path); |
| 182 | updatedTask = metadataTaskInfo; |
| 183 | } |
| 184 | } else { |
| 185 | this.pendingTaskInfoByPath.delete(file.path); |
| 186 | } |
| 187 | } |
| 188 | filterIndexChanged = this.updateFilterIndexesForFile(file.path, cache); |
| 189 | |
| 190 | // Emit both the generic file event and the task-specific event so rendered task cards |
| 191 | // refresh when users edit task frontmatter directly in Obsidian. |
| 192 | this.trigger("file-updated", { path: file.path, file, updatedTask, filterIndexChanged }); |
| 193 | if (updatedTask) { |
| 194 | this.trigger(EVENT_TASK_UPDATED, { |
| 195 | path: file.path, |
| 196 | task: updatedTask, |
| 197 | taskInfo: updatedTask, |
| 198 | updatedTask, |
| 199 | }); |
| 200 | } |
| 201 | this.trigger("data-changed"); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Handle file deletion |
no test coverage detected