Skip to content

Commit 6fcf92d

Browse files
authored
Merge pull request #13 from RefactorSecurity/fix-comment-deletion
Fix comment deletion
2 parents 3957330 + e12c0af commit 6fcf92d

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ export function activate(context: vscode.ExtensionContext) {
108108
'security-notes.deleteNote',
109109
(thread: vscode.CommentThread) => {
110110
thread.dispose();
111+
if (thread.contextValue) {
112+
noteMap.delete(thread.contextValue);
113+
}
111114
},
112115
),
113116
);

src/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export const mergeThread = (local: vscode.CommentThread, remote: any): boolean =
109109
(a.timestamp ? Number(a.timestamp) : 0) - (b.timestamp ? Number(b.timestamp) : 0),
110110
);
111111

112+
// mark all merged comments as deletable, except for the first one
113+
mergedComments.slice(1).forEach((comment) => (comment.contextValue = 'canDelete'));
114+
112115
// assigned unique and sorted comments to current thread
113116
local.comments = mergedComments;
114117
return merged;

src/models/noteComment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ export class NoteComment implements vscode.Comment {
2424
} else {
2525
this.timestamp = new Date();
2626
}
27+
this.contextValue = contextValue;
2728
}
2829
}

src/persistence/serialization/deserializer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class Deserializer {
3535
{ name: comment.author },
3636
parent,
3737
deserializedReactions,
38-
undefined,
38+
parent && parent.comments.length ? 'canDelete' : undefined,
3939
comment.timestamp,
4040
);
4141
return newComment;
@@ -61,6 +61,12 @@ export class Deserializer {
6161
deserializedComments.push(this.deserializeComment(comment, newThread));
6262
});
6363
newThread.comments = deserializedComments;
64+
65+
// mark all comments as deletable, except for the first one
66+
newThread.comments
67+
.slice(1)
68+
.forEach((comment) => (comment.contextValue = 'canDelete'));
69+
6470
return newThread;
6571
}
6672

0 commit comments

Comments
 (0)