* 移除高亮 * @param file 文件 * @param highlight 高亮信息 * @returns 是否成功移除
(file: TFile, highlight: HiNote)
| 73 | * @returns 是否成功移除 |
| 74 | */ |
| 75 | async removeHighlight(file: TFile, highlight: HiNote): Promise<boolean> { |
| 76 | const filePath = file.path; |
| 77 | const fileHighlights = await this.repository.getFileHighlights(filePath); |
| 78 | |
| 79 | const highlightExists = fileHighlights.some(h => h.id === highlight.id); |
| 80 | if (!highlightExists) { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | const updatedHighlights = fileHighlights.filter(h => h.id !== highlight.id); |
| 85 | |
| 86 | if (updatedHighlights.length > 0) { |
| 87 | await this.repository.saveFileHighlights(filePath, updatedHighlights); |
| 88 | } else { |
| 89 | await this.repository.deleteFileHighlights(filePath); |
| 90 | } |
| 91 | |
| 92 | if (this.eventManager && highlight.id) { |
| 93 | if (highlight.comments && highlight.comments.length > 0) { |
| 94 | const latestComment = highlight.comments[highlight.comments.length - 1]; |
| 95 | this.eventManager.emitCommentDelete(filePath, latestComment.content, highlight.id); |
| 96 | } else { |
| 97 | this.eventManager.emitHighlightDelete(filePath, highlight.text, highlight.id); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * 获取文件的所有高亮 |
no test coverage detected