From 3e57581b2dbe1ce48c66306348107a445c4e8f37 Mon Sep 17 00:00:00 2001 From: HeroBlackInk Date: Thu, 26 Feb 2026 19:33:42 +0800 Subject: [PATCH] fix(conflict): preserve todoist tag and guard empty due-date parsing --- src/data/taskParser.ts | 5 +++- src/ui/modals.ts | 63 ++---------------------------------------- 2 files changed, 6 insertions(+), 62 deletions(-) diff --git a/src/data/taskParser.ts b/src/data/taskParser.ts index 29c0dcb..aa61cae 100644 --- a/src/data/taskParser.ts +++ b/src/data/taskParser.ts @@ -466,11 +466,14 @@ export class TaskParser { //this.plugin.debugLog(dateStr); // 输出 2023-03-27 ISOStringToLocalDateString(utcTimeString:string) { try { - if(utcTimeString === null){ + if(!utcTimeString){ return null } let utcDateString = utcTimeString; let dateObj = new Date(utcDateString); // 将UTC格式字符串转换为Date对象 + if (Number.isNaN(dateObj.getTime())) { + return null + } let year = dateObj.getFullYear(); let month = (dateObj.getMonth() + 1).toString().padStart(2, '0'); let date = dateObj.getDate().toString().padStart(2, '0'); diff --git a/src/ui/modals.ts b/src/ui/modals.ts index 93188f0..1dc1d55 100644 --- a/src/ui/modals.ts +++ b/src/ui/modals.ts @@ -1120,69 +1120,10 @@ export class TaskManagerModal extends Modal { } const todoistDueDate = task.due?.date || ''; await fileOperation.syncTaskDueDateToFile(taskId, todoistDueDate); - // Invalidate file cache after content/date writes so tag/priority sync reads fresh data + await fileOperation.syncTaskLabelsToFile(taskId, task.labels || []); + await fileOperation.syncTaskPriorityToFile(taskId, task.priority || 1); this._fileCache.delete(filePath); - // Sync tags (labels) from Todoist to file - const todoistLabels = taskParser.normalizeLabelsForCompare([...(task.labels || []), 'todoist']); let currentLine = await this.getTaskLine(taskId, filePath); - if (currentLine && todoistLabels.length > 0) { - const existingTags = taskParser.getAllTagsFromLineText(currentLine); - let updatedLine = currentLine; - for (const tag of existingTags) { - updatedLine = updatedLine.replace(new RegExp(`#${tag}\\b`, 'g'), ''); - } - // Add Todoist labels as tags before #todoist - const todoistTagPos = updatedLine.indexOf('#todoist'); - if (todoistTagPos > 0) { - const labelTags = todoistLabels.map((l: string) => `#${l}`).join(' '); - updatedLine = updatedLine.substring(0, todoistTagPos) + labelTags + ' ' + updatedLine.substring(todoistTagPos); - } - // Clean up multiple spaces - updatedLine = updatedLine.replace(/ +/g, ' '); - if (updatedLine !== currentLine) { - const file = this.app.vault.getAbstractFileByPath(filePath); - if (file instanceof TFile) { - const fileContent = await this.app.vault.read(file); - const newContent = fileContent.replace(currentLine, updatedLine); - await this.app.vault.modify(file, newContent); - this._fileCache.delete(filePath); - } - } - } - // Sync priority from Todoist to file - currentLine = await this.getTaskLine(taskId, filePath); - if (currentLine) { - const todoistPriority = task.priority || 1; - const existingPriorityMatch = currentLine.match(/\s!!(\d)\s/); - const existingPriority = existingPriorityMatch ? parseInt(existingPriorityMatch[1]) : 1; - if (todoistPriority !== existingPriority) { - let updatedLine: string; - if (existingPriorityMatch) { - updatedLine = currentLine.replace(/\s!!(\d)\s/, ` !!${todoistPriority} `); - } else if (todoistPriority > 1) { - // Insert priority before #todoist - const todoistTagPos = currentLine.indexOf('#todoist'); - if (todoistTagPos > 0) { - updatedLine = currentLine.substring(0, todoistTagPos) + `!!${todoistPriority} ` + currentLine.substring(todoistTagPos); - } else { - updatedLine = currentLine + ` !!${todoistPriority}`; - } - } else { - updatedLine = currentLine; - } - if (updatedLine !== currentLine) { - const file = this.app.vault.getAbstractFileByPath(filePath); - if (file instanceof TFile) { - const fileContent = await this.app.vault.read(file); - const newContent = fileContent.replace(currentLine, updatedLine); - await this.app.vault.modify(file, newContent); - this._fileCache.delete(filePath); - } - } - } - } - // Sync completion status - currentLine = await this.getTaskLine(taskId, filePath); const obsidianChecked = currentLine ? /\[(x|X)\]/.test(currentLine) : false; const todoistChecked = task.checked || false; if (todoistChecked && !obsidianChecked) {