MCPcopy Create free account
hub / github.com/CatMuse/HiNote / addHighlight

Method addHighlight

src/services/HighlightManager.ts:30–67  ·  view source on GitHub ↗

* 添加或更新高亮 * @param file 文件 * @param highlight 高亮信息 * @returns 添加的高亮

(file: TFile, highlight: HiNote)

Source from the content-addressed store, hash-verified

28 * @returns 添加的高亮
29 */
30 async addHighlight(file: TFile, highlight: HiNote): Promise<HiNote> {
31 if (!highlight.id) {
32 highlight.id = IdGenerator.generateHighlightId(
33 file.path,
34 highlight.position || 0,
35 highlight.text
36 );
37 }
38
39 const now = Date.now();
40 if (!highlight.createdAt) {
41 highlight.createdAt = now;
42 }
43 highlight.updatedAt = now;
44
45 const filePath = file.path;
46 const fileHighlights = await this.repository.getFileHighlights(filePath);
47 const existingIndex = fileHighlights.findIndex(h => h.id === highlight.id);
48
49 if (existingIndex >= 0) {
50 fileHighlights[existingIndex] = highlight;
51 } else {
52 fileHighlights.push(highlight);
53 }
54
55 await this.repository.saveFileHighlights(filePath, fileHighlights);
56
57 if (this.eventManager) {
58 if (highlight.comments && highlight.comments.length > 0) {
59 const latestComment = highlight.comments[highlight.comments.length - 1];
60 this.eventManager.emitCommentUpdate(filePath, highlight.text, latestComment.content, highlight.id);
61 } else {
62 this.eventManager.emitHighlightUpdate(filePath, highlight.text, highlight.text, highlight.id);
63 }
64 }
65
66 return highlight;
67 }
68
69 /**
70 * 移除高亮

Callers 6

createFlashcardMethod · 0.80
handleAddFileCommentMethod · 0.80
addCommentMethod · 0.80
updateCommentMethod · 0.80
deleteCommentMethod · 0.80
saveAnswerFromEditorMethod · 0.80

Calls 5

generateHighlightIdMethod · 0.80
emitCommentUpdateMethod · 0.80
emitHighlightUpdateMethod · 0.80
getFileHighlightsMethod · 0.65
saveFileHighlightsMethod · 0.65

Tested by

no test coverage detected