* 更新评论
(highlight: HighlightInfo, commentId: string, content: string)
| 126 | * 更新评论 |
| 127 | */ |
| 128 | async updateComment(highlight: HighlightInfo, commentId: string, content: string): Promise<void> { |
| 129 | const file = await this.getFileForHighlight(highlight); |
| 130 | if (!file || !highlight.comments) return; |
| 131 | |
| 132 | const comment = highlight.comments.find(c => c.id === commentId); |
| 133 | if (comment) { |
| 134 | const oldContent = comment.content; |
| 135 | |
| 136 | comment.content = content; |
| 137 | comment.updatedAt = Date.now(); |
| 138 | highlight.updatedAt = Date.now(); |
| 139 | await this.highlightManager.addHighlight(file, highlight); |
| 140 | |
| 141 | // 通过 EventManager 触发批注更新事件,用于闪卡同步 |
| 142 | if (highlight.id) { |
| 143 | this.plugin.eventManager.emitCommentUpdate(file.path, oldContent, content, highlight.id); |
| 144 | } |
| 145 | |
| 146 | // 只更新单个卡片,而不是刷新整个视图 |
| 147 | if (this.onCardUpdate) { |
| 148 | this.onCardUpdate(highlight); |
| 149 | } else if (this.onRefreshView) { |
| 150 | // 降级方案:如果没有 onCardUpdate,则刷新整个视图 |
| 151 | await this.onRefreshView(); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * 删除评论 |
no test coverage detected